diff --git a/client/init.ts b/client/init.ts index 54cfb35..235093a 100644 --- a/client/init.ts +++ b/client/init.ts @@ -36,6 +36,3 @@ const onResize = () => { // deno-lint-ignore no-window no-window-prefix window.addEventListener('resize', onResize) onResize() - -const config = await fetch('/config.json').then((re) => re.json()) -config.title && (document.title = config.title) diff --git a/client/ui/app-state/AppStateContextWrapper.tsx b/client/ui/app-state/AppStateContextWrapper.tsx index 55f9e35..0bbd17c 100644 --- a/client/ui/app-state/AppStateContextWrapper.tsx +++ b/client/ui/app-state/AppStateContextWrapper.tsx @@ -10,6 +10,10 @@ 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" + +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([]) @@ -41,6 +45,10 @@ export default function DialogContextWrapper({ children, useRef }: { children: R const [useChatFragmentDialog, setUseChatFragmentDialog] = React.useState(false) const chatFragmentDialogRef = React.useRef() + useAsyncEffect(async () => { + document.title = (currentSelectedChatId && currentSelectedChatId != '' && await ClientCache.getChat(currentSelectedChatId).then((v) => v?.getTitle()) + ' | ') + (config.title || 'LingChair') + }, [currentSelectedChatId]) + return