File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 );
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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 }
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 }
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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 };
Original file line number Diff line number Diff line change 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 }
Original file line number Diff line number Diff line change 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 }
You can’t perform that action at this time.
0 commit comments