From ae0e7fee95c171f458901220f28b0ec1b59f8eea Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 13 Dec 2025 18:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E8=B5=84=E6=96=99=E5=8D=A1?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/Main.tsx | 7 +- client/ui/routers/UserOrChatInfoDialog.tsx | 71 +++++++++++-------- .../routers/UserOrChatInfoDialogDataLoader.ts | 2 + 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/client/ui/Main.tsx b/client/ui/Main.tsx index a633e86..d7f2e2c 100644 --- a/client/ui/Main.tsx +++ b/client/ui/Main.tsx @@ -3,7 +3,7 @@ import useEventListener from "../utils/useEventListener.ts" import AvatarMySelf from "./AvatarMySelf.tsx" import MainSharedContext from './MainSharedContext.ts' import * as React from 'react' -import { BrowserRouter, createBrowserRouter, Link, LoaderFunction, Outlet, Route, RouterProvider, Routes } from "react-router" +import { BrowserRouter, createBrowserRouter, Link, LoaderFunction, Outlet, Route, RouterProvider, Routes, useNavigate } from "react-router" import LoginDialog from "./main-page/LoginDialog.tsx" import useAsyncEffect from "../utils/useAsyncEffect.ts" import performAuth from "../performAuth.ts" @@ -23,6 +23,7 @@ import UserOrChatInfoDialogLoader from "./routers/UserOrChatInfoDialogDataLoader import ChatFragmentDialog from "./routers/ChatFragmentDialog.tsx" import EffectOnly from "./EffectOnly.tsx" import MainSharedReducer from "./MainSharedReducer.ts" +import gotoUserInfo from "./routers/gotoUserInfo.ts" function Root() { const [myProfileCache, setMyProfileCache] = React.useState() @@ -52,6 +53,8 @@ function Root() { const [showRegisterDialog, setShowRegisterDialog] = React.useState(false) const [showAddFavourtieChatDialog, setShowAddFavourtieChatDialog] = React.useState(false) + const nav = useNavigate() + const [state, dispatch] = React.useReducer(MainSharedReducer, { favouriteChats: [], currentSelectedChatId: '', @@ -116,7 +119,7 @@ function Root() { - + gotoUserInfo(nav, myProfileCache!.getId())}> {myProfileCache?.getNickName()} diff --git a/client/ui/routers/UserOrChatInfoDialog.tsx b/client/ui/routers/UserOrChatInfoDialog.tsx index e6471dc..b0882c1 100644 --- a/client/ui/routers/UserOrChatInfoDialog.tsx +++ b/client/ui/routers/UserOrChatInfoDialog.tsx @@ -17,7 +17,9 @@ export default function UserOrChatInfoDialog() { })) const dialogRef = useRouterDialogRef() - const { chat, id } = useLoaderData() + const { chat, id, mySelf } = useLoaderData() + + const isMySelf = mySelf?.getId() == id const favourited = React.useMemo(() => shared.state.favouriteChats.map((v) => v.getId()).indexOf(chat.getId() || '') != -1, [chat, shared.state.favouriteChats]) @@ -53,37 +55,44 @@ export default function UserOrChatInfoDialog() { marginTop: "10px", }}> - dialog({ - headline: favourited ? "取消收藏对话" : "收藏对话", - description: favourited ? "确定从收藏对话列表中移除吗? (虽然这不会导致聊天记录丢失)" : "确定要添加到收藏对话列表吗?", - actions: [ - { - text: "取消", - onClick: () => { - return true + { + isMySelf && + 编辑资料 + + } + { + !isMySelf && dialog({ + headline: favourited ? "取消收藏对话" : "收藏对话", + description: favourited ? "确定从收藏对话列表中移除吗? (虽然这不会导致聊天记录丢失)" : "确定要添加到收藏对话列表吗?", + actions: [ + { + text: "取消", + onClick: () => { + return true + }, }, - }, - { - text: "确定", - onClick: () => { - ; (async () => { - try { - if (favourited) - await (await ClientCache.getMySelf())!.removeFavouriteChatsOrThrow([chat.getId()]) - else - await (await ClientCache.getMySelf())!.addFavouriteChatsOrThrow([chat.getId()]) - } catch (e) { - if (e instanceof CallbackError) - showSnackbar({ - message: (favourited ? "取消收藏对话" : "收藏对话") + '失败: ' + e.message - }) - } - })() - return true - }, - } - ], - })}>{favourited ? '取消收藏' : '收藏对话'} + { + text: "确定", + onClick: () => { + ; (async () => { + try { + if (favourited) + await (await ClientCache.getMySelf())!.removeFavouriteChatsOrThrow([chat.getId()]) + else + await (await ClientCache.getMySelf())!.addFavouriteChatsOrThrow([chat.getId()]) + } catch (e) { + if (e instanceof CallbackError) + showSnackbar({ + message: (favourited ? "取消收藏对话" : "收藏对话") + '失败: ' + e.message + }) + } + })() + return true + }, + } + ], + })}>{favourited ? '取消收藏' : '收藏对话'} + } { }}>打开对话 diff --git a/client/ui/routers/UserOrChatInfoDialogDataLoader.ts b/client/ui/routers/UserOrChatInfoDialogDataLoader.ts index e559871..7a71c11 100644 --- a/client/ui/routers/UserOrChatInfoDialogDataLoader.ts +++ b/client/ui/routers/UserOrChatInfoDialogDataLoader.ts @@ -1,6 +1,7 @@ import { LoaderFunctionArgs } from "react-router" import getClient from "../../getClient" import { Chat } from "lingchair-client-protocol" +import ClientCache from "../../ClientCache" export default async function UserOrChatInfoDialogLoader({ params, request }: LoaderFunctionArgs) { const searchParams = new URL(request.url).searchParams @@ -16,6 +17,7 @@ export default async function UserOrChatInfoDialogLoader({ params, request }: Lo id = await chat.getTheOtherUserIdOrThrow() return { + mySelf: await ClientCache.getMySelf(), chat, id, }