From 16bacea5e34ee260284a3ad736c91cf768f53645 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 13 Dec 2025 18:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84=E6=89=93?= =?UTF-8?q?=E5=BC=80=E8=B5=84=E6=96=99=E5=8D=A1=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/main-page/AllChatsList.tsx | 19 +++++++++------- client/ui/main-page/FavouriteChatsList.tsx | 25 +++++++++++----------- client/ui/main-page/RecentChatsList.tsx | 10 ++++----- client/ui/routers/gotoChatInfo.ts | 5 +++++ client/ui/routers/gotoUserInfo.ts | 5 +++++ 5 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 client/ui/routers/gotoChatInfo.ts create mode 100644 client/ui/routers/gotoUserInfo.ts diff --git a/client/ui/main-page/AllChatsList.tsx b/client/ui/main-page/AllChatsList.tsx index 7fc204a..e41a2b9 100644 --- a/client/ui/main-page/AllChatsList.tsx +++ b/client/ui/main-page/AllChatsList.tsx @@ -3,24 +3,27 @@ import React from "react" import AllChatsListItem from "./AllChatsListItem.tsx" import useEventListener from "../../utils/useEventListener.ts" import useAsyncEffect from "../../utils/useAsyncEffect.ts" -import { CallbackError, Chat, UserMySelf } from "lingchair-client-protocol" -import getClient from "../../getClient.ts" +import { CallbackError, Chat } from "lingchair-client-protocol" import showSnackbar from "../../utils/showSnackbar.ts" import isMobileUI from "../../utils/isMobileUI.ts" import { useContextSelector } from "use-context-selector" import MainSharedContext, { Shared } from "../MainSharedContext.ts" +import ClientCache from "../../ClientCache.ts" +import gotoChatInfo from "../routers/gotoChatInfo.ts" +import { useNavigate } from "react-router" export default function AllChatsList({ ...props }: React.HTMLAttributes) { const shared = useContextSelector(MainSharedContext, (context: Shared) => ({ - myProfileCache: context.myProfileCache, functions_lazy: context.functions_lazy, - currentSelectedChatId: context.currentSelectedChatId, + state: context.state, })) const searchRef = React.useRef(null) const [searchText, setSearchText] = React.useState('') const [allChatsList, setAllChatsList] = React.useState([]) + const nav = useNavigate() + useEventListener(searchRef, 'input', (e) => { setSearchText((e.target as unknown as TextField).value) }) @@ -28,7 +31,7 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes { async function updateAllChats() { try { - setAllChatsList(await shared.myProfileCache!.getMyAllChatsOrThrow()) + setAllChatsList(await (await ClientCache.getMySelf())!.getMyAllChatsOrThrow()) } catch (e) { if (e instanceof CallbackError) if (e.code != 401 && e.code != 400) @@ -40,7 +43,7 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes { } }) @@ -69,10 +72,10 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes { - openChatInfoDialog(v) + gotoChatInfo(nav, v.getId()) }} chat={v} /> ) diff --git a/client/ui/main-page/FavouriteChatsList.tsx b/client/ui/main-page/FavouriteChatsList.tsx index a0ac0a4..8035b94 100644 --- a/client/ui/main-page/FavouriteChatsList.tsx +++ b/client/ui/main-page/FavouriteChatsList.tsx @@ -3,19 +3,19 @@ import FavouriteChatsListItem from "./FavouriteChatsListItem.tsx" import { dialog, TextField } from "mdui" import useAsyncEffect from "../../utils/useAsyncEffect.ts" import useEventListener from "../../utils/useEventListener.ts" -import { CallbackError, Chat, UserMySelf } from "lingchair-client-protocol" +import { CallbackError, Chat } from "lingchair-client-protocol" import showSnackbar from "../../utils/showSnackbar.ts" -import getClient from "../../getClient.ts" import { useContextSelector } from "use-context-selector" import MainSharedContext, { Shared } from "../MainSharedContext.ts" import isMobileUI from "../../utils/isMobileUI.ts" +import gotoChatInfo from "../routers/gotoChatInfo.ts" +import ClientCache from "../../ClientCache.ts" +import { useNavigate } from "react-router" export default function FavouriteChatsList({ ...props }: React.HTMLAttributes) { const shared = useContextSelector(MainSharedContext, (context: Shared) => ({ - myProfileCache: context.myProfileCache, setShowAddFavourtieChatDialog: context.setShowAddFavourtieChatDialog, - favouriteChats: context.favouriteChats, - currentSelectedChatId: context.currentSelectedChatId, + state: context.state, functions_lazy: context.functions_lazy, })) @@ -25,6 +25,8 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes([]) const [checkedList, setCheckedList] = React.useState<{ [key: string]: boolean }>({}) + const nav = useNavigate() + useEventListener(searchRef, 'input', (e) => { setSearchText((e.target as unknown as TextField).value) }) @@ -32,9 +34,8 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes { async function updateFavouriteChats() { try { - const ls = await shared.myProfileCache!.getMyFavouriteChatsOrThrow() + const ls = await (await ClientCache.getMySelf())!.getMyFavouriteChatsOrThrow() setFavouriteChatsList(ls) - shared.favouriteChats } catch (e) { if (e instanceof CallbackError) if (e.code != 401 && e.code != 400) @@ -50,7 +51,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes { } - }, [shared.myProfileCache]) + }, []) return checkedList[chatId] == true) try { - shared.myProfileCache!.removeFavouriteChatsOrThrow(ls) + (await ClientCache.getMySelf())!.removeFavouriteChatsOrThrow(ls) setCheckedList({}) setIsMultiSelecting(false) @@ -118,7 +119,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes { try { - shared.myProfileCache!.addFavouriteChatsOrThrow(ls) + (await ClientCache.getMySelf())!.addFavouriteChatsOrThrow(ls) } catch (e) { if (e instanceof CallbackError) showSnackbar({ @@ -152,7 +153,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes { if (isMultiSelecting) setCheckedList({ @@ -160,7 +161,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes diff --git a/client/ui/main-page/RecentChatsList.tsx b/client/ui/main-page/RecentChatsList.tsx index adf4b07..60ce9da 100644 --- a/client/ui/main-page/RecentChatsList.tsx +++ b/client/ui/main-page/RecentChatsList.tsx @@ -10,12 +10,12 @@ import { CallbackError } from "lingchair-client-protocol" import { useContextSelector } from "use-context-selector" import showSnackbar from "../../utils/showSnackbar.ts" import MainSharedContext, { Shared } from "../MainSharedContext.ts" +import ClientCache from "../../ClientCache.ts" export default function RecentChatsList({ ...props }: React.HTMLAttributes) { const shared = useContextSelector(MainSharedContext, (context: Shared) => ({ - myProfileCache: context.myProfileCache, functions_lazy: context.functions_lazy, - currentSelectedChatId: context.currentSelectedChatId, + state: context.state, })) const searchRef = React.useRef(null) @@ -29,7 +29,7 @@ export default function RecentChatsList({ ...props }: React.HTMLAttributes { async function updateRecents() { try { - setRecentsList(await shared.myProfileCache!.getMyRecentChats()) + setRecentsList(await (await ClientCache.getMySelf())!.getMyRecentChats()) } catch (e) { if (e instanceof CallbackError) if (e.code != 401 && e.code != 400) @@ -73,8 +73,8 @@ export default function RecentChatsList({ ...props }: React.HTMLAttributes openChatFragment(v.getId())} + active={isMobileUI() ? false : shared.state.currentSelectedChatId == v.getId()} + onClick={() => {}} key={v.getId()} recentChat={v} /> ) diff --git a/client/ui/routers/gotoChatInfo.ts b/client/ui/routers/gotoChatInfo.ts new file mode 100644 index 0000000..20ab059 --- /dev/null +++ b/client/ui/routers/gotoChatInfo.ts @@ -0,0 +1,5 @@ +import { NavigateFunction } from "react-router" + +export default function gotoChatInfo(nav: NavigateFunction, id: string) { + nav('/info/chat?id=' + id) +} diff --git a/client/ui/routers/gotoUserInfo.ts b/client/ui/routers/gotoUserInfo.ts new file mode 100644 index 0000000..5e59dea --- /dev/null +++ b/client/ui/routers/gotoUserInfo.ts @@ -0,0 +1,5 @@ +import { NavigateFunction } from "react-router" + +export default function gotoUserInfo(nav: NavigateFunction, id: string) { + nav('/info/user?id=' + id) +}