import { memo, useState } from "react"; import { useMatch, useParams } from "react-router-dom"; import clsx from "clsx"; import { useAppSelector } from "@/app/store"; import BlankPlaceholder from "@/components/BlankPlaceholder"; import ChannelModal from "@/components/ChannelModal"; import ErrorCatcher from "@/components/ErrorCatcher"; import Server from "@/components/Server"; import UsersModal from "@/components/UsersModal"; import ChannelChat from "./ChannelChat"; import DMChat from "./DMChat"; import GuestBlankPlaceholder from "./GuestBlankPlaceholder"; import GuestChannelChat from "./GuestChannelChat"; import GuestSessionList from "./GuestSessionList"; import RTCWidget from "./RTCWidget"; import SessionList from "./SessionList"; import VoiceFullscreen from "./VoiceFullscreen"; function ChatPage() { const isHomePath = useMatch(`/`); const isChatHomePath = useMatch(`/chat`); const [sessionListVisible, setSessionListVisible] = useState(false); const [channelModalVisible, setChannelModalVisible] = useState(false); const [usersModalVisible, setUsersModalVisible] = useState(false); const { channel_id = 0, user_id = 0 } = useParams(); const { sessionUids, isGuest, aside = "", callingTo } = useAppSelector((store) => { return { callingTo: store.voice.callingTo, isGuest: store.authData.guest, sessionUids: store.userMessage.ids, aside: channel_id ? store.footprint.channelAsides[+channel_id] : store.footprint.dmAsides[store.voice.callingTo] }; }); const toggleUsersModalVisible = () => { setUsersModalVisible((prev) => !prev); }; const toggleChannelModalVisible = () => { setChannelModalVisible((prev) => !prev); }; const toggleSessionList = () => { setSessionListVisible((prev) => !prev); }; const tmpSession = user_id == 0 ? undefined : sessionUids.findIndex((i) => i == +user_id) == -1 ? { mid: 0, unread: 0, id: +user_id, type: "dm" as const } : undefined; // console.log("temp uid", tmpUid); const placeholderVisible = channel_id == 0 && user_id == 0; const voiceFullscreenVisible = aside === "voice_fullscreen"; const channelChatVisible = channel_id != 0 && aside !== "voice_fullscreen"; const dmChatVisible = user_id != 0 && aside !== "voice_fullscreen"; const isMainPath = isHomePath || isChatHomePath; const context = channel_id !== 0 ? "channel" : "dm"; const contextId = (+channel_id || callingTo) ?? 0; console.log("fffff", channel_id, user_id, aside, channelChatVisible); return ( {channelModalVisible && ( )} {usersModalVisible && }
{sessionListVisible && (
)}
{isGuest ? : }
{voiceFullscreenVisible && } {placeholderVisible && (isGuest ? : )} {channelChatVisible && (isGuest ? : )} {dmChatVisible && }
); } export default memo(ChatPage);