<commit_before>import React from "react";
import Room from "../room/Room.jsx";
import Lobby from "../lobby/Lobby.jsx";
import Settings from "../settings/Settings.jsx";
import Header from "../header/Header.jsx";
import { connect } from "react-redux";
import styled from "styled-components";
import { changeActiveRoom, changePresent } from "../users/localUserActions";
import { hasAnyUnreadMention, getActiveRoom, getTotalUnreadMessageCount } from "../../selectors/selectors";

const Container = styled.div`
	display: flex;
	flex-direction: column;
	width: 100vw;
	height: 100vh;
`;

const mapStateToProps = (state, ownProps) => {
	const sectionMatch = /2\/(\w+)/.exec(ownProps.location.pathname);
	return {
		loaded: state.localUser.loaded,
		section: sectionMatch ? sectionMatch[1] : null,
		rooms: state.rooms,
		activeRoom: getActiveRoom(state),
		totalUnreadMessageCount: getTotalUnreadMessageCount(state),
		anyUnreadMention: hasAnyUnreadMention(state)
	};
};

const mapDispatchToProps = dispatch => ({
	changeActiveRoom: roomId => {
		dispatch(changeActiveRoom(roomId));
	},
	changePresent: present => {
		dispatch(changePresent(present));
	}
});

class Chat extends React.PureComponent {
	componentDidMount() {
		window.document.addEventListener("visibilitychange", () => {
			this.props.changePresent(document.visibilityState === "visible");
		});
	}

	componentDidUpdate(prevProps) {
		const previousActiveRoom = prevProps.activeRoom || { _id: "prevlobby" };
		const activeRoom = this.props.activeRoom || { _id: "currlobby" };
		if (previousActiveRoom._id !== activeRoom._id) {
			this.props.changeActiveRoom(activeRoom._id || null);
		}

		const unread =
			this.props.totalUnreadMessageCount > 0
				? `${this.props.anyUnreadMention ? "*" : ""}(${this.props.totalUnreadMessageCount}) `
				: "";

		// Set title
		switch (this.props.section) {
			case "settings":
				document.title = `${unread}Settings - Bunker`;
				break;
			case "room":
				document.title = `${unread}${activeRoom.name} - Bunker`;
				break;
			default:
				document.title = `${unread}Bunker`;
				break;<commit_msg>fix bug with active room from lobby/settings<commit_after>import React from "react";
import Room from "../room/Room.jsx";
import Lobby from "../lobby/Lobby.jsx";
import Settings from "../settings/Settings.jsx";
import Header from "../header/Header.jsx";
import { connect } from "react-redux";
import styled from "styled-components";
import { changeActiveRoom, changePresent } from "../users/localUserActions";
import { hasAnyUnreadMention, getActiveRoom, getTotalUnreadMessageCount } from "../../selectors/selectors";

const Container = styled.div`
	display: flex;
	flex-direction: column;
	width: 100vw;
	height: 100vh;
`;

const mapStateToProps = (state, ownProps) => {
	const sectionMatch = /2\/(\w+)/.exec(ownProps.location.pathname);
	return {
		loaded: state.localUser.loaded,
		section: sectionMatch ? sectionMatch[1] : null,
		rooms: state.rooms,
		activeRoom: getActiveRoom(state),
		totalUnreadMessageCount: getTotalUnreadMessageCount(state),
		anyUnreadMention: hasAnyUnreadMention(state)
	};
};

const mapDispatchToProps = dispatch => ({
	changeActiveRoom: roomId => {
		dispatch(changeActiveRoom(roomId));
	},
	changePresent: present => {
		dispatch(changePresent(present));
	}
});

class Chat extends React.PureComponent {
	componentDidMount() {
		window.document.addEventListener("visibilitychange", () => {
			this.props.changePresent(document.visibilityState === "visible");
		});
	}

	componentDidUpdate(prevProps) {
		const previousActiveRoom = prevProps.activeRoom || { _id: "prevlobby" };
		const activeRoom = this.props.activeRoom || { _id: "currlobby" };
		if (previousActiveRoom._id !== activeRoom._id) {
			this.props.changeActiveRoom(this.props.activeRoom ? this.props.activeRoom._id : null);
		}

		const unread =
			this.props.totalUnreadMessageCount > 0
				? `${this.props.anyUnreadMention ? "*" : ""}(${this.props.totalUnreadMessageCount}) `
				: "";

		// Set title
		switch (this.props.section) {
			case "settings":
				document.title = `${unread}Settings - Bunker`;
				break;
			case "room":
				document.title = `${unread}${activeRoom.name} - Bunker`;
				break;
			default:
				document.title = `${unread}Bunker`;
				break;
{'fraction_non_alphanumeric': 0.14902605022295237, 'fraction_numerical': 0.004224360478760855, 'mean_word_length': 4.5785340314136125, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3920200', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1348, 'n_words': 268}