prevent duplicate entries in friends page

This commit is contained in:
Nuwan 2024-04-12 19:39:55 +05:30
parent edb6bd0b90
commit bd45275107
1 changed files with 20 additions and 4 deletions

View File

@ -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'