feat: search contact by nickname/id/username
This commit is contained in:
@@ -152,10 +152,11 @@ export default function App() {
|
|||||||
// 最近聊天
|
// 最近聊天
|
||||||
<RecentsList
|
<RecentsList
|
||||||
openChatFragment={(id) => {
|
openChatFragment={(id) => {
|
||||||
|
setCurrentChatId(id)
|
||||||
setIsShowChatFragment(true)
|
setIsShowChatFragment(true)
|
||||||
|
|
||||||
}}
|
}}
|
||||||
display={navigationItemSelected == "Recents"}
|
display={navigationItemSelected == "Recents"}
|
||||||
|
currentChatId={currentChatId}
|
||||||
recentsList={recentsList}
|
recentsList={recentsList}
|
||||||
setRecentsList={setRecentsList} />
|
setRecentsList={setRecentsList} />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
import ContactsListItem from "./ContactsListItem.tsx"
|
import ContactsListItem from "./ContactsListItem.tsx"
|
||||||
|
import useEventListener from "../useEventListener.ts"
|
||||||
|
import { TextField } from "mdui";
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
contactsList: User[]
|
contactsList: User[]
|
||||||
@@ -16,6 +18,13 @@ export default function ContactsList({
|
|||||||
openChatFragment,
|
openChatFragment,
|
||||||
...props
|
...props
|
||||||
}: Args) {
|
}: Args) {
|
||||||
|
const searchRef = React.useRef<HTMLElement>(null)
|
||||||
|
const [searchText, setSearchText] = React.useState('')
|
||||||
|
|
||||||
|
useEventListener(searchRef, 'input', (e) => {
|
||||||
|
setSearchText((e.target as unknown as TextField).value)
|
||||||
|
})
|
||||||
|
|
||||||
return <mdui-list style={{
|
return <mdui-list style={{
|
||||||
overflowY: 'auto',
|
overflowY: 'auto',
|
||||||
paddingLeft: '10px',
|
paddingLeft: '10px',
|
||||||
@@ -23,15 +32,26 @@ export default function ContactsList({
|
|||||||
display: display ? undefined : 'none',
|
display: display ? undefined : 'none',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
}} {...props}>
|
}} {...props}>
|
||||||
|
<mdui-text-field icon="search" type="search" clearable ref={searchRef} variant="outlined" label="搜索..." style={{
|
||||||
|
marginTop: '5px',
|
||||||
|
}}></mdui-text-field>
|
||||||
|
|
||||||
<mdui-list-item rounded style={{
|
<mdui-list-item rounded style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
marginTop: '13px',
|
||||||
|
marginBottom: '15px',
|
||||||
}} icon="person_add">添加聯絡人</mdui-list-item>
|
}} icon="person_add">添加聯絡人</mdui-list-item>
|
||||||
{
|
{
|
||||||
contactsList.map((v2) =>
|
contactsList.filter((user) =>
|
||||||
|
searchText == '' ||
|
||||||
|
user.nickname.includes(searchText) ||
|
||||||
|
user.id.includes(searchText) ||
|
||||||
|
user.username?.includes(searchText)
|
||||||
|
).map((v) =>
|
||||||
<ContactsListItem
|
<ContactsListItem
|
||||||
openChatFragment={openChatFragment}
|
openChatFragment={openChatFragment}
|
||||||
key={v2.id}
|
key={v.id}
|
||||||
contact={v2} />
|
contact={v} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</mdui-list>
|
</mdui-list>
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ interface Args extends React.HTMLAttributes<HTMLElement> {
|
|||||||
recentsList: RecentChat[]
|
recentsList: RecentChat[]
|
||||||
setRecentsList: React.Dispatch<React.SetStateAction<RecentChat[]>>
|
setRecentsList: React.Dispatch<React.SetStateAction<RecentChat[]>>
|
||||||
display: boolean
|
display: boolean
|
||||||
|
currentChatId: string
|
||||||
openChatFragment: (id: string) => void
|
openChatFragment: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RecentsList({
|
export default function RecentsList({
|
||||||
recentsList,
|
recentsList,
|
||||||
setRecentsList,
|
setRecentsList,
|
||||||
|
currentChatId,
|
||||||
display,
|
display,
|
||||||
openChatFragment,
|
openChatFragment,
|
||||||
...props
|
...props
|
||||||
@@ -24,7 +26,8 @@ export default function RecentsList({
|
|||||||
{
|
{
|
||||||
recentsList.map((v) =>
|
recentsList.map((v) =>
|
||||||
<RecentsListItem
|
<RecentsListItem
|
||||||
openChatFragment={openChatFragment}
|
active={currentChatId == v.id}
|
||||||
|
openChatFragment={() => openChatFragment(v.id)}
|
||||||
key={v.id}
|
key={v.id}
|
||||||
recentChat={v} />
|
recentChat={v} />
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,15 +4,16 @@ import Avatar from "../Avatar.tsx"
|
|||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
recentChat: RecentChat
|
recentChat: RecentChat
|
||||||
openChatFragment: (id: string) => void
|
openChatFragment: (id: string) => void
|
||||||
|
active?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RecentsListItem({ recentChat, openChatFragment }: Args) {
|
export default function RecentsListItem({ recentChat, openChatFragment, active }: Args) {
|
||||||
const { id, title, avatar, content } = recentChat
|
const { id, title, avatar, content } = recentChat
|
||||||
return (
|
return (
|
||||||
<mdui-list-item rounded style={{
|
<mdui-list-item rounded style={{
|
||||||
marginTop: '3px',
|
marginTop: '3px',
|
||||||
marginBottom: '3px',
|
marginBottom: '3px',
|
||||||
}} onClick={() => openChatFragment(id)}>
|
}} onClick={() => openChatFragment(id)} active={active}>
|
||||||
{title}
|
{title}
|
||||||
<Avatar src={avatar} text={title} slot="icon" />
|
<Avatar src={avatar} text={title} slot="icon" />
|
||||||
<span slot="description"
|
<span slot="description"
|
||||||
|
|||||||
Reference in New Issue
Block a user