From bd45275107eb77c8863b10f75af0ebded638f4e9 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Fri, 12 Apr 2024 19:39:55 +0530 Subject: [PATCH] prevent duplicate entries in friends page --- jam-ui/src/store/features/peopleSlice.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/jam-ui/src/store/features/peopleSlice.js b/jam-ui/src/store/features/peopleSlice.js index e6cb78c38..f3ba7f2da 100644 --- a/jam-ui/src/store/features/peopleSlice.js +++ b/jam-ui/src/store/features/peopleSlice.js @@ -80,8 +80,16 @@ export const peopleSlice = createSlice({ state.status = 'loading' }) .addCase(fetchPeople.fulfilled, (state, action) => { - const records = [...state.people, ...action.payload.musicians]; - state.people = records + // const records = [...state.people, ...action.payload.musicians]; + // state.people = records + // state.hasOffset = !!action.payload.offset + // state.offset = action.payload.offset + // state.status = 'succeeded' + //--- + const records = new Set([...state.people, ...action.payload.musicians]); + const unique = []; + records.map(x => unique.filter(p => p.id === x.id).length > 0 ? null : unique.push(x)) + state.people = unique state.hasOffset = !!action.payload.offset state.offset = action.payload.offset state.status = 'succeeded' @@ -94,8 +102,16 @@ export const peopleSlice = createSlice({ state.status = 'loading' }) .addCase(preFetchPeople.fulfilled, (state, action) => { - const records = [...state.prefetched, ...action.payload.musicians]; - state.prefetched = records + // const records = [...state.prefetched, ...action.payload.musicians]; + // state.prefetched = records + // state.hasOffset = !!action.payload.offset + // state.offset = action.payload.offset + // state.status = 'succeeded' + //--- + const records = new Set([...state.prefetched, ...action.payload.musicians]); + const unique = []; + records.map(x => unique.filter(p => p.id === x.id).length > 0 ? null : unique.push(x)) + state.people = unique state.hasOffset = !!action.payload.offset state.offset = action.payload.offset state.status = 'succeeded'