使用新的打开资料卡方式

This commit is contained in:
CrescentLeaf
2025-12-13 18:03:35 +08:00
parent 22bf643d5e
commit 16bacea5e3
5 changed files with 39 additions and 25 deletions

View File

@@ -3,24 +3,27 @@ import React from "react"
import AllChatsListItem from "./AllChatsListItem.tsx" import AllChatsListItem from "./AllChatsListItem.tsx"
import useEventListener from "../../utils/useEventListener.ts" import useEventListener from "../../utils/useEventListener.ts"
import useAsyncEffect from "../../utils/useAsyncEffect.ts" import useAsyncEffect from "../../utils/useAsyncEffect.ts"
import { CallbackError, Chat, UserMySelf } from "lingchair-client-protocol" import { CallbackError, Chat } from "lingchair-client-protocol"
import getClient from "../../getClient.ts"
import showSnackbar from "../../utils/showSnackbar.ts" import showSnackbar from "../../utils/showSnackbar.ts"
import isMobileUI from "../../utils/isMobileUI.ts" import isMobileUI from "../../utils/isMobileUI.ts"
import { useContextSelector } from "use-context-selector" import { useContextSelector } from "use-context-selector"
import MainSharedContext, { Shared } from "../MainSharedContext.ts" 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<HTMLElement>) { export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElement>) {
const shared = useContextSelector(MainSharedContext, (context: Shared) => ({ const shared = useContextSelector(MainSharedContext, (context: Shared) => ({
myProfileCache: context.myProfileCache,
functions_lazy: context.functions_lazy, functions_lazy: context.functions_lazy,
currentSelectedChatId: context.currentSelectedChatId, state: context.state,
})) }))
const searchRef = React.useRef<HTMLElement>(null) const searchRef = React.useRef<HTMLElement>(null)
const [searchText, setSearchText] = React.useState('') const [searchText, setSearchText] = React.useState('')
const [allChatsList, setAllChatsList] = React.useState<Chat[]>([]) const [allChatsList, setAllChatsList] = React.useState<Chat[]>([])
const nav = useNavigate()
useEventListener(searchRef, 'input', (e) => { useEventListener(searchRef, 'input', (e) => {
setSearchText((e.target as unknown as TextField).value) setSearchText((e.target as unknown as TextField).value)
}) })
@@ -28,7 +31,7 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElem
useAsyncEffect(async () => { useAsyncEffect(async () => {
async function updateAllChats() { async function updateAllChats() {
try { try {
setAllChatsList(await shared.myProfileCache!.getMyAllChatsOrThrow()) setAllChatsList(await (await ClientCache.getMySelf())!.getMyAllChatsOrThrow())
} catch (e) { } catch (e) {
if (e instanceof CallbackError) if (e instanceof CallbackError)
if (e.code != 401 && e.code != 400) if (e.code != 401 && e.code != 400)
@@ -69,10 +72,10 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElem
chat.getId().includes(searchText) chat.getId().includes(searchText)
).map((v) => ).map((v) =>
<AllChatsListItem <AllChatsListItem
active={isMobileUI() ? false : shared.currentSelectedChatId == v.getId()} active={isMobileUI() ? false : shared.state.currentSelectedChatId == v.getId()}
key={v.getId()} key={v.getId()}
onClick={() => { onClick={() => {
openChatInfoDialog(v) gotoChatInfo(nav, v.getId())
}} }}
chat={v} /> chat={v} />
) )

View File

@@ -3,19 +3,19 @@ import FavouriteChatsListItem from "./FavouriteChatsListItem.tsx"
import { dialog, TextField } from "mdui" import { dialog, TextField } from "mdui"
import useAsyncEffect from "../../utils/useAsyncEffect.ts" import useAsyncEffect from "../../utils/useAsyncEffect.ts"
import useEventListener from "../../utils/useEventListener.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 showSnackbar from "../../utils/showSnackbar.ts"
import getClient from "../../getClient.ts"
import { useContextSelector } from "use-context-selector" import { useContextSelector } from "use-context-selector"
import MainSharedContext, { Shared } from "../MainSharedContext.ts" import MainSharedContext, { Shared } from "../MainSharedContext.ts"
import isMobileUI from "../../utils/isMobileUI.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<HTMLElement>) { export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HTMLElement>) {
const shared = useContextSelector(MainSharedContext, (context: Shared) => ({ const shared = useContextSelector(MainSharedContext, (context: Shared) => ({
myProfileCache: context.myProfileCache,
setShowAddFavourtieChatDialog: context.setShowAddFavourtieChatDialog, setShowAddFavourtieChatDialog: context.setShowAddFavourtieChatDialog,
favouriteChats: context.favouriteChats, state: context.state,
currentSelectedChatId: context.currentSelectedChatId,
functions_lazy: context.functions_lazy, functions_lazy: context.functions_lazy,
})) }))
@@ -25,6 +25,8 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
const [favouriteChatsList, setFavouriteChatsList] = React.useState<Chat[]>([]) const [favouriteChatsList, setFavouriteChatsList] = React.useState<Chat[]>([])
const [checkedList, setCheckedList] = React.useState<{ [key: string]: boolean }>({}) const [checkedList, setCheckedList] = React.useState<{ [key: string]: boolean }>({})
const nav = useNavigate()
useEventListener(searchRef, 'input', (e) => { useEventListener(searchRef, 'input', (e) => {
setSearchText((e.target as unknown as TextField).value) setSearchText((e.target as unknown as TextField).value)
}) })
@@ -32,9 +34,8 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
useAsyncEffect(async () => { useAsyncEffect(async () => {
async function updateFavouriteChats() { async function updateFavouriteChats() {
try { try {
const ls = await shared.myProfileCache!.getMyFavouriteChatsOrThrow() const ls = await (await ClientCache.getMySelf())!.getMyFavouriteChatsOrThrow()
setFavouriteChatsList(ls) setFavouriteChatsList(ls)
shared.favouriteChats
} catch (e) { } catch (e) {
if (e instanceof CallbackError) if (e instanceof CallbackError)
if (e.code != 401 && e.code != 400) if (e.code != 401 && e.code != 400)
@@ -50,7 +51,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
return () => { return () => {
} }
}, [shared.myProfileCache]) }, [])
return <mdui-list style={{ return <mdui-list style={{
overflowY: 'auto', overflowY: 'auto',
@@ -106,7 +107,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
const ls = Object.keys(checkedList).filter((chatId) => checkedList[chatId] == true) const ls = Object.keys(checkedList).filter((chatId) => checkedList[chatId] == true)
try { try {
shared.myProfileCache!.removeFavouriteChatsOrThrow(ls) (await ClientCache.getMySelf())!.removeFavouriteChatsOrThrow(ls)
setCheckedList({}) setCheckedList({})
setIsMultiSelecting(false) setIsMultiSelecting(false)
@@ -118,7 +119,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
action: "撤销操作", action: "撤销操作",
onActionClick: async () => { onActionClick: async () => {
try { try {
shared.myProfileCache!.addFavouriteChatsOrThrow(ls) (await ClientCache.getMySelf())!.addFavouriteChatsOrThrow(ls)
} catch (e) { } catch (e) {
if (e instanceof CallbackError) if (e instanceof CallbackError)
showSnackbar({ showSnackbar({
@@ -152,7 +153,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
chat.getId().includes(searchText) chat.getId().includes(searchText)
).map((v) => ).map((v) =>
<FavouriteChatsListItem <FavouriteChatsListItem
active={isMultiSelecting ? checkedList[v.getId()] == true : (isMobileUI() ? false : shared.currentSelectedChatId == v.getId())} active={isMultiSelecting ? checkedList[v.getId()] == true : (isMobileUI() ? false : shared.state.currentSelectedChatId == v.getId())}
onClick={() => { onClick={() => {
if (isMultiSelecting) if (isMultiSelecting)
setCheckedList({ setCheckedList({
@@ -160,7 +161,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
[v.getId()]: !checkedList[v.getId()], [v.getId()]: !checkedList[v.getId()],
}) })
else else
openChatInfoDialog(v) gotoChatInfo(nav, v.getId())
}} }}
key={v.getId()} key={v.getId()}
chat={v} /> chat={v} />

View File

@@ -10,12 +10,12 @@ import { CallbackError } from "lingchair-client-protocol"
import { useContextSelector } from "use-context-selector" import { useContextSelector } from "use-context-selector"
import showSnackbar from "../../utils/showSnackbar.ts" import showSnackbar from "../../utils/showSnackbar.ts"
import MainSharedContext, { Shared } from "../MainSharedContext.ts" import MainSharedContext, { Shared } from "../MainSharedContext.ts"
import ClientCache from "../../ClientCache.ts"
export default function RecentChatsList({ ...props }: React.HTMLAttributes<HTMLElement>) { export default function RecentChatsList({ ...props }: React.HTMLAttributes<HTMLElement>) {
const shared = useContextSelector(MainSharedContext, (context: Shared) => ({ const shared = useContextSelector(MainSharedContext, (context: Shared) => ({
myProfileCache: context.myProfileCache,
functions_lazy: context.functions_lazy, functions_lazy: context.functions_lazy,
currentSelectedChatId: context.currentSelectedChatId, state: context.state,
})) }))
const searchRef = React.useRef<HTMLElement>(null) const searchRef = React.useRef<HTMLElement>(null)
@@ -29,7 +29,7 @@ export default function RecentChatsList({ ...props }: React.HTMLAttributes<HTMLE
useAsyncEffect(async () => { useAsyncEffect(async () => {
async function updateRecents() { async function updateRecents() {
try { try {
setRecentsList(await shared.myProfileCache!.getMyRecentChats()) setRecentsList(await (await ClientCache.getMySelf())!.getMyRecentChats())
} catch (e) { } catch (e) {
if (e instanceof CallbackError) if (e instanceof CallbackError)
if (e.code != 401 && e.code != 400) if (e.code != 401 && e.code != 400)
@@ -73,8 +73,8 @@ export default function RecentChatsList({ ...props }: React.HTMLAttributes<HTMLE
chat.getContent().includes(searchText) chat.getContent().includes(searchText)
).map((v) => ).map((v) =>
<RecentsListItem <RecentsListItem
active={isMobileUI() ? false : shared.currentSelectedChatId == v.getId()} active={isMobileUI() ? false : shared.state.currentSelectedChatId == v.getId()}
openChatFragment={() => openChatFragment(v.getId())} onClick={() => {}}
key={v.getId()} key={v.getId()}
recentChat={v} /> recentChat={v} />
) )

View File

@@ -0,0 +1,5 @@
import { NavigateFunction } from "react-router"
export default function gotoChatInfo(nav: NavigateFunction, id: string) {
nav('/info/chat?id=' + id)
}

View File

@@ -0,0 +1,5 @@
import { NavigateFunction } from "react-router"
export default function gotoUserInfo(nav: NavigateFunction, id: string) {
nav('/info/user?id=' + id)
}