import isMobileUI from "../utils/isMobileUI.ts" import useEventListener from "../utils/useEventListener.ts" import AvatarMySelf from "./AvatarMySelf.tsx" import MainSharedContext from './MainSharedContext.ts' import * as React from 'react' import { BrowserRouter, Link, Outlet, Route, Routes } from "react-router" import LoginDialog from "./main-page/LoginDialog.tsx" import useAsyncEffect from "../utils/useAsyncEffect.ts" import performAuth from "../performAuth.ts" import { CallbackError, Chat, UserMySelf } from "lingchair-client-protocol" import showCircleProgressDialog from "./showCircleProgressDialog.ts" import RegisterDialog from "./main-page/RegisterDialog.tsx" import sleep from "../utils/sleep.ts" import { $, NavigationDrawer } from "mdui" import getClient from "../getClient.ts" import showSnackbar from "../utils/showSnackbar.ts" import AllChatsList from "./main-page/AllChatsList.tsx" import FavouriteChatsList from "./main-page/FavouriteChatsList.tsx" import AddFavourtieChatDialog from "./main-page/AddFavourtieChatDialog.tsx" import RecentChatsList from "./main-page/RecentChatsList.tsx" import ChatInfoDialog from "./routers/ChatInfoDialog.tsx" export default function Main() { const [myProfileCache, setMyProfileCache] = React.useState() // 多页面切换 const navigationRef = React.useRef() const [currentShowPage, setCurrentShowPage] = React.useState('Recents') type HTMLElementWithValue = HTMLElement & { value: string } useEventListener(navigationRef, 'change', (event) => { setCurrentShowPage((event.target as HTMLElementWithValue).value) }) const drawerRef = React.useRef() React.useEffect(() => { $(drawerRef.current!.shadowRoot).append(` `) }, []) const [showLoginDialog, setShowLoginDialog] = React.useState(false) const [showRegisterDialog, setShowRegisterDialog] = React.useState(false) const [showAddFavourtieChatDialog, setShowAddFavourtieChatDialog] = React.useState(false) const [currentSelectedChatId, setCurrentSelectedChatId] = React.useState('') const [favouriteChats, setFavouriteChats] = React.useState([]) const sharedContext = { functions_lazy: React.useRef({ updateFavouriteChats: () => { }, updateRecentChats: () => { }, updateAllChats: () => { }, }), favouriteChats, setFavouriteChats, setShowLoginDialog, setShowRegisterDialog, setShowAddFavourtieChatDialog, currentSelectedChatId, setCurrentSelectedChatId, myProfileCache, } useAsyncEffect(async () => { const waitingForAuth = showCircleProgressDialog("加载中...") try { await performAuth({}) try { setMyProfileCache(await UserMySelf.getMySelfOrThrow(getClient())) } catch (e) { if (e instanceof CallbackError) showSnackbar({ message: '获取资料失败: ' + e.message }) } } catch (e) { if (e instanceof CallbackError) if (e.code == 401 || e.code == 400) setShowLoginDialog(true) } // 动画都没来得及, 稍微等一下 ( await sleep(100) waitingForAuth.open = false }) const subRoutes = <> } /> } /> return ( { // 将子路由渲染到此处 } {myProfileCache?.getNickName()} 账号设置 添加收藏对话 创建新的群组 我是测试 我是测试2
LingChair Web v{__APP_VERSION__}
Build: {__GIT_HASH__} ({__BUILD_TIME__})
在 Codeberg 上查看源代码
{ /** * Default: 侧边列表提供列表切换 */ !isMobileUI() ? drawerRef.current!.open = true}> /** * Mobile: 底部导航栏提供列表切换 */ : drawerRef.current!.open = true}> { ({ Recents: "最近对话", Favourites: "收藏对话", AllChats: "所有对话", })[currentShowPage] }
} { /** * Mobile: 指定高度的容器 * Default: 侧边列表 */ } { /** * Mobile: 底部导航栏提供列表切换 * Default: 侧边列表提供列表切换 */ isMobileUI() && 最近对话 收藏对话 全部对话 } )}> {subRoutes}
) }