fix: search chat performance fix
This commit is contained in:
+29
-15
@@ -28,25 +28,44 @@ export default function ChatsSection({ selected, onSelect }: Props) {
|
||||
refetchInterval: 10_000,
|
||||
});
|
||||
|
||||
const chatList = useMemo(() => {
|
||||
return (
|
||||
chats?.map((i) => {
|
||||
const contact = i.accountLid ? contacts.findById(i.accountLid) : null;
|
||||
return {
|
||||
...i,
|
||||
contact,
|
||||
title:
|
||||
i.contact?.formattedName ||
|
||||
i.contact?.name ||
|
||||
i.formattedTitle ||
|
||||
i.name,
|
||||
from: i.isGroup
|
||||
? contacts.findById(i.previewMessage?.author || null)
|
||||
: null,
|
||||
};
|
||||
}) || []
|
||||
);
|
||||
}, [chats, contacts]);
|
||||
|
||||
const filteredChats = useMemo(() => {
|
||||
let items = chats || [];
|
||||
let items = chatList || [];
|
||||
|
||||
if (query.trim().length > 0) {
|
||||
items = items.filter(
|
||||
(chat) =>
|
||||
chat.name?.toLowerCase().includes(query.toLowerCase()) ||
|
||||
chat.formattedTitle?.toLowerCase().includes(query.toLowerCase()) ||
|
||||
chat.contact?.name?.toLowerCase().includes(query.toLowerCase()) ||
|
||||
chat.contact?.formattedName
|
||||
?.toLowerCase()
|
||||
.includes(query.toLowerCase()) ||
|
||||
chat.lastMessage?.body?.toLowerCase().includes(query.toLowerCase()),
|
||||
);
|
||||
}
|
||||
|
||||
return items.slice(0, 100).map((i) => ({
|
||||
...i,
|
||||
contact: i.accountLid ? contacts.findById(i.accountLid) : null,
|
||||
from: i.isGroup
|
||||
? contacts.findById(i.previewMessage?.author || null)
|
||||
: null,
|
||||
}));
|
||||
}, [chats, query]);
|
||||
return items.slice(0, 100);
|
||||
}, [chatList, query]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -92,12 +111,7 @@ export default function ChatsSection({ selected, onSelect }: Props) {
|
||||
: null}
|
||||
|
||||
{filteredChats?.map((chat) => {
|
||||
const title =
|
||||
chat.contact?.formattedName ||
|
||||
chat.contact?.name ||
|
||||
chat.formattedTitle ||
|
||||
chat.name ||
|
||||
"No title";
|
||||
const title = chat.title || "No title";
|
||||
|
||||
return (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user