feat(wip): 聯絡人/群組對話框, 並打開對應的對話

This commit is contained in:
CrescentLeaf
2025-09-21 02:14:39 +08:00
parent 6f006f38a4
commit 3d367711cc
2 changed files with 33 additions and 42 deletions

View File

@@ -18,6 +18,8 @@ import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
import ContactsList from "./main/ContactsList.tsx" import ContactsList from "./main/ContactsList.tsx"
import RecentsList from "./main/RecentsList.tsx" import RecentsList from "./main/RecentsList.tsx"
import useAsyncEffect from "./useAsyncEffect.ts" import useAsyncEffect from "./useAsyncEffect.ts"
import ChatInfoDialog from "./dialog/ChatInfoDialog.tsx";
import Chat from "../api/client_data/Chat.ts";
declare global { declare global {
namespace React { namespace React {
@@ -31,32 +33,7 @@ declare global {
} }
export default function App() { export default function App() {
const [recentsList, setRecentsList] = React.useState([ const [recentsList, setRecentsList] = React.useState([] as RecentChat[])
{
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 [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents') const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents')
@@ -80,7 +57,10 @@ export default function App() {
userProfileDialogRef.current!.open = true userProfileDialogRef.current!.open = true
}) })
const [myUserProfileCache, setMyUserProfileCache]: [User, React.Dispatch<React.SetStateAction<User>>] = React.useState(null as unknown as User) const chatInfoDialogRef = React.useRef<Dialog>(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) const [isShowChatFragment, setIsShowChatFragment] = React.useState(false)
@@ -133,6 +113,14 @@ export default function App() {
userProfileDialogRef={userProfileDialogRef as any} userProfileDialogRef={userProfileDialogRef as any}
user={myUserProfileCache} /> user={myUserProfileCache} />
<ChatInfoDialog
chatInfoDialogRef={chatInfoDialogRef as any}
openChatFragment={(id) => {
setCurrentChatId(id)
setIsShowChatFragment(true)
}}
chat={chatInfo} />
<mdui-navigation-rail contained value="Recents" ref={navigationRailRef}> <mdui-navigation-rail contained value="Recents" ref={navigationRailRef}>
<mdui-button-icon slot="top"> <mdui-button-icon slot="top">
<Avatar src={myUserProfileCache?.avatar} text={myUserProfileCache?.nickname} avatarRef={openMyUserProfileDialogButtonRef} /> <Avatar src={myUserProfileCache?.avatar} text={myUserProfileCache?.nickname} avatarRef={openMyUserProfileDialogButtonRef} />
@@ -162,9 +150,8 @@ export default function App() {
{ {
// 联系人列表 // 联系人列表
<ContactsList <ContactsList
openChatFragment={(id) => { setChatInfo={setChatInfo}
setIsShowChatFragment(true) chatInfoDialogRef={chatInfoDialogRef as any}
}}
display={navigationItemSelected == "Contacts"} /> display={navigationItemSelected == "Contacts"} />
} }
</div> </div>

View File

@@ -4,20 +4,28 @@ import useAsyncEffect from "../useAsyncEffect.ts"
import Client from "../../api/Client.ts" import Client from "../../api/Client.ts"
import data from "../../Data.ts" import data from "../../Data.ts"
import { Dialog } from "mdui" import { Dialog } from "mdui"
import Avatar from "../Avatar.tsx";
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
interface Args extends React.HTMLAttributes<HTMLElement> { interface Args extends React.HTMLAttributes<HTMLElement> {
chat: Chat chat: Chat
openChatFragment: (id: string) => void
chatInfoDialogRef: React.MutableRefObject<Dialog> chatInfoDialogRef: React.MutableRefObject<Dialog>
} }
export default function ChatInfoDialog({ chat, chatInfoDialogRef }: Args) { export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment }: Args) {
const [isMySelf, setIsMySelf] = React.useState(false) 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 () => { useAsyncEffect(async () => {
if (chat == null) return
const re = await Client.invoke("Chat.getInfo", { const re = await Client.invoke("Chat.getInfo", {
token: data.access_token, token: data.access_token,
target: chat.id, target: chat.id,
}) })
if (re.code != 200)
return checkApiSuccessOrSncakbar(re, '獲取對話訊息失敗')
setChatInfo(re.data!.chat_info as Chat)
}) })
return ( return (
@@ -26,14 +34,14 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef }: Args) {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
}}> }}>
<Avatar src={chat?.avatar} text={chat?.nickname} style={{ <Avatar src={chat?.avatar as string} text={chat?.nickname as string} style={{
width: '50px', width: '50px',
height: '50px', height: '50px',
}} /> }} />
<span style={{ <span style={{
marginLeft: "15px", marginLeft: "15px",
fontSize: '16.5px', fontSize: '16.5px',
}}>{user?.nickname}</span> }}>{chat?.title}</span>
</div> </div>
<mdui-divider style={{ <mdui-divider style={{
marginTop: "10px", marginTop: "10px",
@@ -41,14 +49,10 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef }: Args) {
}}></mdui-divider> }}></mdui-divider>
<mdui-list> <mdui-list>
{!isMySelf && <mdui-list-item icon="edit" rounded></mdui-list-item>} <mdui-list-item icon="chat" rounded onClick={() => {
{ chatInfoDialogRef.current!.open = false
isMySelf && <> openChatFragment(chat.id)
<mdui-list-item icon="edit" rounded></mdui-list-item> }}></mdui-list-item>
<mdui-list-item icon="settings" rounded></mdui-list-item>
<mdui-list-item icon="lock" rounded></mdui-list-item>
</>
}
</mdui-list> </mdui-list>
</mdui-dialog> </mdui-dialog>
) )