Skip to content

Commit 5b6c29a

Browse files
committed
fix applying the new sorting state
1 parent 6c38149 commit 5b6c29a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/stores/preferences.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import arrayMove from 'array-move'
12
import { Occupation } from 'src/features/onboarding/types'
23
import { Tag } from 'src/features/remoteConfig'
34
import { enhanceTags } from 'src/utils/DataEnhancement'
@@ -76,11 +77,13 @@ export const useUserPreferences = create(
7677
})),
7778
setUserCustomCards: (cards: SupportedCardType[]) => set({ userCustomCards: cards }),
7879
updateCardOrder: (prevIndex: number, newIndex: number) => set((state) => {
79-
const newState = state.cards;
80-
81-
const temp = newState[prevIndex].id;
82-
newState[prevIndex].id = newState[newIndex].id;
83-
newState[newIndex].id = temp;
80+
81+
const newState = arrayMove(state.cards, prevIndex, newIndex).map((card, index) => {
82+
return {
83+
...card,
84+
id: index
85+
}
86+
})
8487

8588
return { cards: newState}
8689
}),

0 commit comments

Comments
 (0)