"use client"; require("../polyfill"); import { useState, useEffect } from "react"; import styles from "./home.module.scss"; import BotIcon from "../icons/bot.svg"; import LoadingIcon from "../icons/three-dots.svg"; import { getCSSVar, useMobileScreen } from "../utils"; import dynamic from "next/dynamic"; import { Path, SlotID } from "../constant"; import { ErrorBoundary } from "./error"; import { HashRouter as Router, Routes, Route, useLocation, } from "react-router-dom"; import { SideBar } from "./sidebar"; import { useAppConfig } from "../store/config"; export function Loading(props: { noLogo?: boolean }) { return (
{!props.noLogo && }
); } const Settings = dynamic(async () => (await import("./settings")).Settings, { loading: () => , }); const Chat = dynamic(async () => (await import("./chat")).Chat, { loading: () => , }); const NewChat = dynamic(async () => (await import("./new-chat")).NewChat, { loading: () => , }); const MaskPage = dynamic(async () => (await import("./mask")).MaskPage, { loading: () => , }); export function useSwitchTheme() { const config = useAppConfig(); useEffect(() => { document.body.classList.remove("light"); document.body.classList.remove("dark"); if (config.theme === "dark") { document.body.classList.add("dark"); } else if (config.theme === "light") { document.body.classList.add("light"); } const metaDescriptionDark = document.querySelector( 'meta[name="theme-color"][media*="dark"]', ); const metaDescriptionLight = document.querySelector( 'meta[name="theme-color"][media*="light"]', ); if (config.theme === "auto") { metaDescriptionDark?.setAttribute("content", "#151515"); metaDescriptionLight?.setAttribute("content", "#fafafa"); } else { const themeColor = getCSSVar("--theme-color"); metaDescriptionDark?.setAttribute("content", themeColor); metaDescriptionLight?.setAttribute("content", themeColor); } }, [config.theme]); } const useHasHydrated = () => { const [hasHydrated, setHasHydrated] = useState(false); useEffect(() => { setHasHydrated(true); }, []); return hasHydrated; }; const loadAsyncGoogleFont = () => { const linkEl = document.createElement("link"); linkEl.rel = "stylesheet"; linkEl.href = "/google-fonts/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap"; document.head.appendChild(linkEl); }; function Screen() { const config = useAppConfig(); const location = useLocation(); const isHome = location.pathname === Path.Home; const isMobileScreen = useMobileScreen(); useEffect(() => { loadAsyncGoogleFont(); }, []); return (
} /> } /> } /> } /> } />
); } export function Home() { useSwitchTheme(); if (!useHasHydrated()) { return ; } return ( ); }