feat: 修復並正式支持聯絡人

* wip(ui): 增刪
This commit is contained in:
CrescentLeaf
2025-09-21 02:13:16 +08:00
parent 468de4f439
commit 791baf474c
4 changed files with 47 additions and 45 deletions

View File

@@ -1,44 +1,42 @@
import React from "react"
import User from "../../api/client_data/User.ts"
import ContactsListItem from "./ContactsListItem.tsx"
import useEventListener from "../useEventListener.ts"
import { ListItem, TextField } from "mdui"
import { Dialog, ListItem, TextField } from "mdui"
import useAsyncEffect from "../useAsyncEffect.ts"
import Client from "../../api/Client.ts"
import data from "../../Data.ts"
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
import Chat from "../../api/client_data/Chat.ts"
interface Args extends React.HTMLAttributes<HTMLElement> {
display: boolean
openChatFragment: (id: string) => void
chatInfoDialogRef: React.MutableRefObject<Dialog>
setChatInfo: React.Dispatch<React.SetStateAction<Chat>>
}
export default function ContactsList({
display,
openChatFragment,
setChatInfo,
chatInfoDialogRef,
...props
}: Args) {
const searchRef = React.useRef<HTMLElement>(null)
const [isMultiSelecting, setIsMultiSelecting] = React.useState(false)
const [searchText, setSearchText] = React.useState('')
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 [contactsList, setContactsList] = React.useState<Chat[]>([])
useEventListener(searchRef, 'input', (e) => {
setSearchText((e.target as unknown as TextField).value)
})
useAsyncEffect(async () => {
const re = await Client.invoke("User.getMyContacts", {
token: data.access_token,
})
if (re.code != 200)
return checkApiSuccessOrSncakbar(re, "获取联络人列表失败")
setContactsList(re.data!.contacts_list as Chat[])
})
return <mdui-list style={{
@@ -63,21 +61,21 @@ export default function ContactsList({
}} icon={ isMultiSelecting ? "done" : "edit"} onClick={() => setIsMultiSelecting(!isMultiSelecting)}>{ isMultiSelecting ? "關閉多選" : "多選模式" }</mdui-list-item> */}
{
contactsList.filter((user) =>
contactsList.filter((chat) =>
searchText == '' ||
user.nickname.includes(searchText) ||
user.id.includes(searchText) ||
user.username?.includes(searchText)
chat.title.includes(searchText) ||
chat.id.includes(searchText)
).map((v) =>
<ContactsListItem
/* active={!isMultiSelecting && false}
// active={!isMultiSelecting && false}
onClick={(e) => {
const self = (e.target as ListItem)
if (isMultiSelecting)
/*if (isMultiSelecting)
self.active = !self.active
else
void(0)
}} */
else*/
setChatInfo(v)
chatInfoDialogRef.current!.open = true
}}
key={v.id}
contact={v} />
)

View File

@@ -1,15 +1,14 @@
import { ListItem } from "mdui";
import User from "../../api/client_data/User.ts"
import Chat from "../../api/client_data/Chat.ts"
import Avatar from "../Avatar.tsx"
import React from 'react'
interface Args extends React.HTMLAttributes<HTMLElement> {
contact: User
contact: Chat
active?: boolean
}
export default function ContactsListItem({ contact, ...prop }: Args) {
const { id, nickname, avatar } = contact
const { id, title, avatar } = contact
const ref = React.useRef<HTMLElement>(null)
return (
@@ -20,8 +19,8 @@ export default function ContactsListItem({ contact, ...prop }: Args) {
}} {...prop as any}>
<span style={{
width: "100%",
}}>{nickname}</span>
<Avatar src={avatar} text="title" slot="icon" />
}}>{title}</span>
<Avatar src={avatar as string} text={title} slot="icon" />
</mdui-list-item>
)
}