"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 { useChatStore } from "../store"; import { getCSSVar, useMobileScreen } from "../utils"; import { Chat } from "./chat"; import dynamic from "next/dynamic"; import { Path } from "../constant"; import { ErrorBoundary } from "./error"; import { HashRouter as Router, Routes, Route, useLocation, } from "react-router-dom"; export function Loading(props: { noLogo?: boolean }) { return (
{!props.noLogo && }
); } const Settings = dynamic(async () => (await import("./settings")).Settings, { loading: () => , }); const SideBar = dynamic(async () => (await import("./sidebar")).SideBar, { loading: () => , }); function useSwitchTheme() { const config = useChatStore((state) => state.config); 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]', ); const metaDescriptionLight = document.querySelector( 'meta[name="theme-color"]:not([media])', ); if (config.theme === "auto") { metaDescriptionDark?.setAttribute("content", "#151515"); metaDescriptionLight?.setAttribute("content", "#fafafa"); } else { const themeColor = getCSSVar("--themeColor"); metaDescriptionDark?.setAttribute("content", themeColor); metaDescriptionLight?.setAttribute("content", themeColor); } }, [config.theme]); } const useHasHydrated = () => { const [hasHydrated, setHasHydrated] = useState(false); useEffect(() => { setHasHydrated(true); }, []); return hasHydrated; }; function WideScreen() { // setting const config = useChatStore((state) => state.config); return (
} /> } /> } />
); } function MobileScreen() { const location = useLocation(); const isHome = location.pathname === Path.Home; return (
} /> } />
); } export function Home() { useSwitchTheme(); const isMobileScreen = useMobileScreen(); if (!useHasHydrated()) { return ; } return ( {isMobileScreen ? : } ); }