add batch weapon/summon methods to collection adapter and mutations
This commit is contained in:
parent
a2e0015a85
commit
13a3905776
2 changed files with 64 additions and 0 deletions
|
|
@ -195,6 +195,23 @@ export class CollectionAdapter extends BaseAdapter {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds multiple weapons to the collection with quantity support
|
||||||
|
* Each quantity > 1 creates multiple collection entries
|
||||||
|
*/
|
||||||
|
async addWeapons(
|
||||||
|
inputs: Array<CollectionWeaponInput & { quantity?: number }>
|
||||||
|
): Promise<CollectionWeapon[]> {
|
||||||
|
// Expand inputs based on quantity
|
||||||
|
const expanded = inputs.flatMap((input) => {
|
||||||
|
const count = input.quantity ?? 1
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const { quantity, ...rest } = input
|
||||||
|
return Array(count).fill(rest) as CollectionWeaponInput[]
|
||||||
|
})
|
||||||
|
return Promise.all(expanded.map((input) => this.addWeapon(input)))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a collection weapon
|
* Updates a collection weapon
|
||||||
*/
|
*/
|
||||||
|
|
@ -257,6 +274,23 @@ export class CollectionAdapter extends BaseAdapter {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds multiple summons to the collection with quantity support
|
||||||
|
* Each quantity > 1 creates multiple collection entries
|
||||||
|
*/
|
||||||
|
async addSummons(
|
||||||
|
inputs: Array<CollectionSummonInput & { quantity?: number }>
|
||||||
|
): Promise<CollectionSummon[]> {
|
||||||
|
// Expand inputs based on quantity
|
||||||
|
const expanded = inputs.flatMap((input) => {
|
||||||
|
const count = input.quantity ?? 1
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const { quantity, ...rest } = input
|
||||||
|
return Array(count).fill(rest) as CollectionSummonInput[]
|
||||||
|
})
|
||||||
|
return Promise.all(expanded.map((input) => this.addSummon(input)))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a collection summon
|
* Updates a collection summon
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,21 @@ export function useAddWeaponToCollection() {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add multiple weapons to collection mutation with quantity support
|
||||||
|
*/
|
||||||
|
export function useAddWeaponsToCollection() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return createMutation(() => ({
|
||||||
|
mutationFn: (inputs: Array<CollectionWeaponInput & { quantity?: number }>) =>
|
||||||
|
collectionAdapter.addWeapons(inputs),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: collectionKeys.weapons() })
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update collection weapon mutation
|
* Update collection weapon mutation
|
||||||
*/
|
*/
|
||||||
|
|
@ -194,6 +209,21 @@ export function useAddSummonToCollection() {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add multiple summons to collection mutation with quantity support
|
||||||
|
*/
|
||||||
|
export function useAddSummonsToCollection() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return createMutation(() => ({
|
||||||
|
mutationFn: (inputs: Array<CollectionSummonInput & { quantity?: number }>) =>
|
||||||
|
collectionAdapter.addSummons(inputs),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: collectionKeys.summons() })
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update collection summon mutation
|
* Update collection summon mutation
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue