From 3d367711ccaa5fd4433fc6278489f39fd282522f Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sun, 21 Sep 2025 02:14:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(wip):=20=E8=81=AF=E7=B5=A1=E4=BA=BA/?= =?UTF-8?q?=E7=BE=A4=E7=B5=84=E5=B0=8D=E8=A9=B1=E6=A1=86,=20=E4=B8=A6?= =?UTF-8?q?=E6=89=93=E9=96=8B=E5=B0=8D=E6=87=89=E7=9A=84=E5=B0=8D=E8=A9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/App.tsx | 47 +++++++++++------------------ client/ui/dialog/ChatInfoDialog.tsx | 28 +++++++++-------- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/client/ui/App.tsx b/client/ui/App.tsx index f30e0eb..e430efb 100644 --- a/client/ui/App.tsx +++ b/client/ui/App.tsx @@ -18,6 +18,8 @@ import UserProfileDialog from "./dialog/UserProfileDialog.tsx" import ContactsList from "./main/ContactsList.tsx" import RecentsList from "./main/RecentsList.tsx" import useAsyncEffect from "./useAsyncEffect.ts" +import ChatInfoDialog from "./dialog/ChatInfoDialog.tsx"; +import Chat from "../api/client_data/Chat.ts"; declare global { namespace React { @@ -31,32 +33,7 @@ declare global { } export default function App() { - const [recentsList, setRecentsList] = React.useState([ - { - id: '0', - avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png", - title: "麻油衣酱", - content: "成步堂君, 我又坐牢了(" - }, - { - id: '1', - avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png", - title: "Maya Fey", - content: "我是绫里真宵, 是一名灵媒师~" - }, - ] as RecentChat[]) - const [contactsList, setContactsList] = React.useState([ - { - id: '1', - avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png", - nickname: "麻油衣酱", - }, - { - id: '0', - avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png", - nickname: "Maya Fey", - }, - ] as User[]) + const [recentsList, setRecentsList] = React.useState([] as RecentChat[]) const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents') @@ -80,7 +57,10 @@ export default function App() { userProfileDialogRef.current!.open = true }) - const [myUserProfileCache, setMyUserProfileCache]: [User, React.Dispatch>] = React.useState(null as unknown as User) + const chatInfoDialogRef = React.useRef(null) + const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat) + + const [myUserProfileCache, setMyUserProfileCache] = React.useState(null as unknown as User) const [isShowChatFragment, setIsShowChatFragment] = React.useState(false) @@ -133,6 +113,14 @@ export default function App() { userProfileDialogRef={userProfileDialogRef as any} user={myUserProfileCache} /> + { + setCurrentChatId(id) + setIsShowChatFragment(true) + }} + chat={chatInfo} /> + @@ -162,9 +150,8 @@ export default function App() { { // 联系人列表 { - setIsShowChatFragment(true) - }} + setChatInfo={setChatInfo} + chatInfoDialogRef={chatInfoDialogRef as any} display={navigationItemSelected == "Contacts"} /> } diff --git a/client/ui/dialog/ChatInfoDialog.tsx b/client/ui/dialog/ChatInfoDialog.tsx index 14e1ab4..e83ae59 100644 --- a/client/ui/dialog/ChatInfoDialog.tsx +++ b/client/ui/dialog/ChatInfoDialog.tsx @@ -4,20 +4,28 @@ import useAsyncEffect from "../useAsyncEffect.ts" import Client from "../../api/Client.ts" import data from "../../Data.ts" import { Dialog } from "mdui" +import Avatar from "../Avatar.tsx"; +import { checkApiSuccessOrSncakbar } from "../snackbar.ts" interface Args extends React.HTMLAttributes { chat: Chat + openChatFragment: (id: string) => void chatInfoDialogRef: React.MutableRefObject } -export default function ChatInfoDialog({ chat, chatInfoDialogRef }: Args) { - const [isMySelf, setIsMySelf] = React.useState(false) +export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment }: Args) { + const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat) + const isMySelf = Client.myUserProfile?.id == chatInfo?.user_a_id && Client.myUserProfile?.id == chatInfo?.user_b_id useAsyncEffect(async () => { + if (chat == null) return const re = await Client.invoke("Chat.getInfo", { token: data.access_token, target: chat.id, }) + if (re.code != 200) + return checkApiSuccessOrSncakbar(re, '獲取對話訊息失敗') + setChatInfo(re.data!.chat_info as Chat) }) return ( @@ -26,14 +34,14 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef }: Args) { display: 'flex', alignItems: 'center', }}> - {user?.nickname} + }}>{chat?.title} - {!isMySelf && 編輯聯絡人訊息} - { - isMySelf && <> - 編輯資料 - 賬號設定 - 隱私設定 - - } + { + chatInfoDialogRef.current!.open = false + openChatFragment(chat.id) + }}>對話 )