Skip to content

Commit 58e78e8

Browse files
committed
refac
1 parent b8ea267 commit 58e78e8

7 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/lib/components/admin/Analytics/AnalyticsModelModal.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@
128128
user_id: c.user_id,
129129
user_name: c.user_name
130130
}));
131-
chatList = [...chatList, ...newChats];
131+
const existingIds = new Set(chatList.map((c) => c.id));
132+
const uniqueNewChats = newChats.filter((c) => !existingIds.has(c.id));
133+
chatList = [...chatList, ...uniqueNewChats];
132134
allChatsLoaded = chats.length < PAGE_SIZE;
133135
} catch (err) {
134136
console.error('Failed to load more chats:', err);

src/lib/components/admin/Users/UserList/UserChatsModal.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@
8181
allChatsLoaded = newChatList.length === 0;
8282
8383
if (newChatList.length > 0) {
84-
chatList = [...chatList, ...newChatList];
84+
const existingIds = new Set(chatList.map((c) => c.id));
85+
const uniqueNewChats = newChatList.filter((c) => !existingIds.has(c.id));
86+
chatList = [...chatList, ...uniqueNewChats];
8587
}
8688
8789
chatListLoading = false;

src/lib/components/chat/MessageInput/InputMenu/Knowledge.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@
7878
}
7979
8080
if (selectedFileItems) {
81-
selectedFileItems = [...selectedFileItems, ...pageItems];
81+
const existingIds = new Set(selectedFileItems.map((item) => item.id));
82+
const newItems = pageItems.filter((item) => !existingIds.has(item.id));
83+
selectedFileItems = [...selectedFileItems, ...newItems];
8284
} else {
8385
selectedFileItems = pageItems;
8486
}
@@ -137,7 +139,9 @@
137139
}
138140
139141
if (items) {
140-
items = [...items, ...pageItems];
142+
const existingIds = new Set(items.map((item) => item.id));
143+
const newItems = pageItems.filter((item) => !existingIds.has(item.id));
144+
items = [...items, ...newItems];
141145
} else {
142146
items = pageItems;
143147
}

src/lib/components/layout/SearchModal.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@
163163
allChatsLoaded = newChatList.length === 0;
164164
165165
if (newChatList.length > 0) {
166-
chatList = [...chatList, ...newChatList];
166+
const existingIds = new Set(chatList.map((c) => c.id));
167+
const uniqueNewChats = newChatList.filter((c) => !existingIds.has(c.id));
168+
chatList = [...chatList, ...uniqueNewChats];
167169
}
168170
169171
chatListLoading = false;

src/lib/components/layout/Sidebar.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@
249249
250250
// once the bottom of the list has been reached (no results) there is no need to continue querying
251251
allChatsLoaded = newChatList.length === 0;
252-
await chats.set([...($chats ? $chats : []), ...newChatList]);
252+
const existingIds = new Set(($chats ?? []).map((c) => c.id));
253+
const uniqueNewChats = newChatList.filter((c) => !existingIds.has(c.id));
254+
await chats.set([...($chats ? $chats : []), ...uniqueNewChats]);
253255
254256
chatListLoading = false;
255257
};

src/lib/components/notes/Notes.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@
221221
}
222222
223223
if (items) {
224-
items = [...items, ...pageItems];
224+
const existingIds = new Set(items.map((item) => item.id));
225+
const newItems = pageItems.filter((item) => !existingIds.has(item.id));
226+
items = [...items, ...newItems];
225227
} else {
226228
items = pageItems;
227229
}

src/lib/components/workspace/Knowledge.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@
101101
}
102102
103103
if (items) {
104-
items = [...items, ...pageItems];
104+
const existingIds = new Set(items.map((item) => item.id));
105+
const newItems = pageItems.filter((item) => !existingIds.has(item.id));
106+
items = [...items, ...newItems];
105107
} else {
106108
items = pageItems;
107109
}

0 commit comments

Comments
 (0)