import { $, Dialog } from "mdui" import AppStateContext, { AppState } from "./AppStateContext" import { Chat, User } from "lingchair-client-protocol" import getClient from "../../getClient" import UserOrChatInfoDialog from "./UserOrChatInfoDialog" import useEffectRef from "../../utils/useEffectRef" import EditMyProfileDialog from "./EditMyProfileDialog" import AddFavourtieChatDialog from "./AddFavourtieChatDialog" import * as React from 'react' import { useContextSelector } from "use-context-selector" import MainSharedContext, { Shared } from "../MainSharedContext" import ChatFragmentDialog from "./ChatFragmentDialog" import useAsyncEffect from "../../utils/useAsyncEffect" import ClientCache from "../../ClientCache" import isMobileUI from "../../utils/isMobileUI" const config = await fetch('/config.json').then((re) => re.json()) export default function DialogContextWrapper({ children, useRef }: { children: React.ReactNode, useRef: React.MutableRefObject }) { const [userOrChatInfoDialogState, setUserOrChatInfoDialogState] = React.useState([]) const lastUserOrChatInfoDialogStateRef = React.useRef() const userOrChatInfoDialogRef = useEffectRef((ref) => { ref.current!.addEventListener('closed', () => { setUserOrChatInfoDialogState([]) }) ref.current!.addEventListener('overlay-click', () => { ref.current!.open = false }) }, []) React.useEffect(() => { userOrChatInfoDialogState.length != 0 && (lastUserOrChatInfoDialogStateRef.current = userOrChatInfoDialogState[userOrChatInfoDialogState.length - 1]) userOrChatInfoDialogRef.current!.open = userOrChatInfoDialogState.length != 0 }, [userOrChatInfoDialogState]) const editMyProfileDialogRef = React.useRef() const addFavouriteChatDialogRef = React.useRef() const setCurrentSelectedChatId = useContextSelector( MainSharedContext, (context: Shared) => context.setCurrentSelectedChatId ) const currentSelectedChatId = useContextSelector( MainSharedContext, (context: Shared) => context.state.currentSelectedChatId ) const chatFragmentDialogRef = React.useRef() useAsyncEffect(async () => { document.title = (currentSelectedChatId && currentSelectedChatId != '' && await ClientCache.getChat(currentSelectedChatId).then((v) => v?.getTitle()) + ' | ') + (config.title || 'LingChair') }, [currentSelectedChatId]) return setCurrentSelectedChatId('')) } else setCurrentSelectedChatId('') } }}> {children} }