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