(WIP) 重构客户端

This commit is contained in:
CrescentLeaf
2025-12-07 18:31:42 +08:00
parent 34d46a85f1
commit 20986af1ba
23 changed files with 714 additions and 347 deletions

View File

@@ -3,19 +3,19 @@ import React from "react"
import AllChatsListItem from "./AllChatsListItem.tsx"
import useEventListener from "../../utils/useEventListener.ts"
import useAsyncEffect from "../../utils/useAsyncEffect.ts"
import { CallbackError, Chat, User, UserMySelf } from "lingchair-client-protocol"
import { CallbackError, Chat, UserMySelf } from "lingchair-client-protocol"
import getClient from "../../getClient.ts"
import showSnackbar from "../../utils/showSnackbar.ts"
import isMobileUI from "../../utils/isMobileUI.ts"
interface Args extends React.HTMLAttributes<HTMLElement> {
display: boolean
currentChatId: string
openChatInfoDialog: (chat: Chat) => void
}
import { useContextSelector } from "use-context-selector"
import MainSharedContext, { Shared } from "../MainSharedContext.ts"
export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElement>) {
const shared = useContextSelector(MainSharedContext, (context: Shared) => ({
myProfileCache: context.myProfileCache,
functions_lazy: context.functions_lazy,
}))
const searchRef = React.useRef<HTMLElement>(null)
const [searchText, setSearchText] = React.useState('')
const [allChatsList, setAllChatsList] = React.useState<Chat[]>([])
@@ -27,16 +27,19 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElem
useAsyncEffect(async () => {
async function updateAllChats() {
try {
setAllChatsList(await (await UserMySelf.getMySelfOrThrow(getClient())).getMyAllChatsOrThrow())
setAllChatsList(await shared.myProfileCache!.getMyAllChatsOrThrow())
} catch (e) {
if (e instanceof CallbackError)
if (e.code == 401 || e.code == 400)
if (e.code != 401 && e.code != 400)
showSnackbar({
message: '获取所有对话失败: ' + e.message
})
}
}
updateAllChats()
shared.functions_lazy.current.updateAllChats = updateAllChats
return () => {
}
})
@@ -48,6 +51,7 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElem
paddingTop: '0',
height: '100%',
width: '100%',
...props?.style,
}} {...props}>
<mdui-text-field icon="search" type="search" clearable ref={searchRef} variant="outlined" placeholder="搜索..." style={{
paddingTop: '12px',