From a19cd9f2ae5692a8108976aaa8ed3d256d52d05f Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Tue, 22 Nov 2022 13:58:08 +0100 Subject: [PATCH] fix: Pagination of event log (#2495) Currently, our event log is keeping all the previous data and then fetching and appending to our state list. This causes duplicates, since we're keeping the existing list and might be getting the same data, but with added events at the end. This fix changes the logic to slice existing data at offset. Which should make sure we only append the new data. Co-authored-by: Fredrik Strand Oseberg Co-authored-by: Fredrik Strand Oseberg --- .../src/hooks/api/getters/useEventSearch/useEventSearch.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts b/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts index 2ada2e7244..e0bdd793fb 100644 --- a/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts +++ b/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts @@ -52,7 +52,10 @@ export const useEventSearch = ( // Append results to the page when more data has been fetched. useEffect(() => { if (data) { - setEvents(prev => [...(prev ?? []), ...data.events]); + setEvents(prev => [ + ...(prev?.slice(0, offset) || []), + ...data.events, + ]); if (data.totalEvents) { setTotalEvents(data.totalEvents); }