use resetQueries for weapon collection mutations
prevents item-shifting issues when sort order changes
This commit is contained in:
parent
574454936c
commit
d1198422fe
1 changed files with 5 additions and 3 deletions
|
|
@ -179,6 +179,8 @@ export function useAddWeaponsToCollection() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update collection weapon mutation
|
* Update collection weapon mutation
|
||||||
|
* Uses resetQueries to clear cache and start fresh, avoiding issues where
|
||||||
|
* items shift between pages after sort-affecting updates (like element changes)
|
||||||
*/
|
*/
|
||||||
export function useUpdateCollectionWeapon() {
|
export function useUpdateCollectionWeapon() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
@ -187,7 +189,7 @@ export function useUpdateCollectionWeapon() {
|
||||||
mutationFn: ({ id, input }: { id: string; input: Partial<CollectionWeaponInput> }) =>
|
mutationFn: ({ id, input }: { id: string; input: Partial<CollectionWeaponInput> }) =>
|
||||||
collectionAdapter.updateWeapon(id, input),
|
collectionAdapter.updateWeapon(id, input),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: collectionKeys.weapons() })
|
queryClient.resetQueries({ queryKey: collectionKeys.weapons() })
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
@ -201,7 +203,7 @@ export function useRemoveWeaponFromCollection() {
|
||||||
return createMutation(() => ({
|
return createMutation(() => ({
|
||||||
mutationFn: (id: string) => collectionAdapter.removeWeapon(id),
|
mutationFn: (id: string) => collectionAdapter.removeWeapon(id),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: collectionKeys.weapons() })
|
queryClient.resetQueries({ queryKey: collectionKeys.weapons() })
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
@ -215,7 +217,7 @@ export function useBulkRemoveWeaponsFromCollection() {
|
||||||
return createMutation(() => ({
|
return createMutation(() => ({
|
||||||
mutationFn: (ids: string[]) => collectionAdapter.removeWeaponsBatch(ids),
|
mutationFn: (ids: string[]) => collectionAdapter.removeWeaponsBatch(ids),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: collectionKeys.weapons() })
|
queryClient.resetQueries({ queryKey: collectionKeys.weapons() })
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue