Skip to content

Commit f09f701

Browse files
committed
perf: add virtual list for friend list #238
1 parent a4f7c09 commit f09f701

File tree

5 files changed

+65
-45
lines changed

5 files changed

+65
-45
lines changed

client/web/src/components/PillTabs.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,13 @@
4343
.ant-tabs-content-holder {
4444
overflow-x: hidden;
4545
overflow-y: auto;
46+
47+
.ant-tabs-content {
48+
height: 100%;
49+
50+
.ant-tabs-tabpane {
51+
height: 100%;
52+
}
53+
}
4654
}
4755
}

client/web/src/components/PillTabs.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ import { Tabs, TabsProps } from 'antd';
22
import React from 'react';
33

44
import './PillTabs.less';
5+
import clsx from 'clsx';
56

67
/**
78
* @example
89
* <PillTabs items={[...]} />
910
*/
1011
export const PillTabs: React.FC<TabsProps> = React.memo((props) => {
1112
return (
12-
<Tabs {...props} className="pill-tabs" type="card" animated={false}>
13+
<Tabs
14+
{...props}
15+
className={clsx(props.className, 'pill-tabs')}
16+
type="card"
17+
animated={false}
18+
>
1319
{props.children}
1420
</Tabs>
1521
);

client/web/src/components/modals/GroupDetail/Member.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const GroupMember: React.FC<{ groupId: string }> = React.memo(
5959

6060
<div className="flex-1 overflow-auto">
6161
<Virtuoso
62-
style={{ height: '100%' }}
62+
className="h-full"
6363
data={isSearching ? filteredGroupMembers : userInfos}
6464
itemContent={(index, item) => renderUser(item)}
6565
/>

client/web/src/routes/Main/Content/Personal/Friends/FriendList.tsx

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Problem } from '@/components/Problem';
2424
import { closeModal, openModal } from '@/components/Modal';
2525
import { SetFriendNickname } from '@/components/modals/SetFriendNickname';
2626
import { Icon } from 'tailchat-design';
27+
import { Virtuoso } from 'react-virtuoso';
2728

2829
/**
2930
* 好友列表
@@ -95,7 +96,7 @@ export const FriendList: React.FC<{
9596
}
9697

9798
return (
98-
<div className="py-2.5 px-5">
99+
<div className="py-2.5 px-5 h-full flex flex-col">
99100
<div>{t('好友列表')}</div>
100101

101102
<Input
@@ -107,50 +108,54 @@ export const FriendList: React.FC<{
107108
onChange={(e) => setSearchText(e.target.value)}
108109
/>
109110

110-
<div>
111-
{searchResult.map((item) => (
112-
<UserListItem
113-
key={item._id}
114-
userId={item._id}
115-
actions={[
116-
<Tooltip key="message" title={t('发送消息')}>
117-
<div>
118-
<IconBtn
119-
icon="mdi:message-text-outline"
120-
onClick={() => handleCreateConverse(item._id)}
121-
/>
122-
</div>
123-
</Tooltip>,
124-
<div key="more">
125-
<Dropdown
126-
menu={{
127-
items: [
128-
{
129-
key: 'setNickname',
130-
onClick: () => handleSetFriendNickname(item._id),
131-
label: isValidStr(item.nickname)
132-
? t('更改好友昵称')
133-
: t('添加好友昵称'),
134-
},
135-
{
136-
key: 'delete',
137-
danger: true,
138-
onClick: () => handleRemoveFriend(item._id),
139-
label: t('删除'),
140-
},
141-
],
142-
}}
143-
trigger={['click']}
144-
placement="bottomRight"
145-
>
111+
<div className="flex-1">
112+
<Virtuoso
113+
className="h-full"
114+
data={searchResult}
115+
itemContent={(index, item) => (
116+
<UserListItem
117+
key={item._id}
118+
userId={item._id}
119+
actions={[
120+
<Tooltip key="message" title={t('发送消息')}>
146121
<div>
147-
<IconBtn icon="mdi:dots-vertical" />
122+
<IconBtn
123+
icon="mdi:message-text-outline"
124+
onClick={() => handleCreateConverse(item._id)}
125+
/>
148126
</div>
149-
</Dropdown>
150-
</div>,
151-
]}
152-
/>
153-
))}
127+
</Tooltip>,
128+
<div key="more">
129+
<Dropdown
130+
menu={{
131+
items: [
132+
{
133+
key: 'setNickname',
134+
onClick: () => handleSetFriendNickname(item._id),
135+
label: isValidStr(item.nickname)
136+
? t('更改好友昵称')
137+
: t('添加好友昵称'),
138+
},
139+
{
140+
key: 'delete',
141+
danger: true,
142+
onClick: () => handleRemoveFriend(item._id),
143+
label: t('删除'),
144+
},
145+
],
146+
}}
147+
trigger={['click']}
148+
placement="bottomRight"
149+
>
150+
<div>
151+
<IconBtn icon="mdi:dots-vertical" />
152+
</div>
153+
</Dropdown>
154+
</div>,
155+
]}
156+
/>
157+
)}
158+
/>
154159
</div>
155160
</div>
156161
);

client/web/src/routes/Main/Content/Personal/Friends/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const FriendPanel: React.FC = React.memo(() => {
2929
return (
3030
<div className="w-full">
3131
<PillTabs
32+
className="h-full"
3233
activeKey={activeKey}
3334
onChange={setActiveKey}
3435
items={_compact([

0 commit comments

Comments
 (0)