add bulk delete mutations for collection items

This commit is contained in:
Justin Edmund 2025-12-19 00:40:04 -08:00
parent 22d459f475
commit a56d8f1870
3 changed files with 105 additions and 0 deletions

View file

@ -144,6 +144,22 @@ export class CollectionAdapter extends BaseAdapter {
})
}
/**
* Removes multiple characters from the collection in a single batch request
*/
async removeCharactersBatch(ids: string[]): Promise<{ deleted: number }> {
if (ids.length === 0) return { deleted: 0 }
const response = await this.request<{
meta: { deleted: number }
}>('/collection/characters/batch_destroy', {
method: 'DELETE',
body: { ids }
})
return response.meta
}
/**
* Gets the IDs of all characters in a user's collection
* Useful for filtering out already-owned characters in the add modal
@ -261,6 +277,22 @@ export class CollectionAdapter extends BaseAdapter {
})
}
/**
* Removes multiple weapons from the collection in a single batch request
*/
async removeWeaponsBatch(ids: string[]): Promise<{ deleted: number }> {
if (ids.length === 0) return { deleted: 0 }
const response = await this.request<{
meta: { deleted: number }
}>('/collection/weapons/batch_destroy', {
method: 'DELETE',
body: { ids }
})
return response.meta
}
// ============================================
// Collection Summons
// ============================================
@ -358,6 +390,22 @@ export class CollectionAdapter extends BaseAdapter {
})
}
/**
* Removes multiple summons from the collection in a single batch request
*/
async removeSummonsBatch(ids: string[]): Promise<{ deleted: number }> {
if (ids.length === 0) return { deleted: 0 }
const response = await this.request<{
meta: { deleted: number }
}>('/collection/summons/batch_destroy', {
method: 'DELETE',
body: { ids }
})
return response.meta
}
// ============================================
// Collection Job Accessories
// ============================================

View file

@ -103,6 +103,20 @@ export function useDeleteCollectionArtifact() {
}))
}
/**
* Delete multiple collection artifacts in a single batch
*/
export function useBulkDeleteCollectionArtifacts() {
const queryClient = useQueryClient()
return createMutation(() => ({
mutationFn: (ids: string[]) => artifactAdapter.deleteCollectionArtifactsBatch(ids),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: artifactKeys.collectionBase })
}
}))
}
// ============================================================================
// Grid Artifact Mutations (Equipped on Characters)
// ============================================================================

View file

@ -129,6 +129,21 @@ export function useRemoveCharacterFromCollection() {
}))
}
/**
* Remove multiple characters from collection in a single batch
*/
export function useBulkRemoveCharactersFromCollection() {
const queryClient = useQueryClient()
return createMutation(() => ({
mutationFn: (ids: string[]) => collectionAdapter.removeCharactersBatch(ids),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: collectionKeys.characters() })
queryClient.invalidateQueries({ queryKey: collectionKeys.characterIds() })
}
}))
}
// ============================================================================
// Weapon Mutations
// ============================================================================
@ -191,6 +206,20 @@ export function useRemoveWeaponFromCollection() {
}))
}
/**
* Remove multiple weapons from collection in a single batch
*/
export function useBulkRemoveWeaponsFromCollection() {
const queryClient = useQueryClient()
return createMutation(() => ({
mutationFn: (ids: string[]) => collectionAdapter.removeWeaponsBatch(ids),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: collectionKeys.weapons() })
}
}))
}
// ============================================================================
// Summon Mutations
// ============================================================================
@ -253,6 +282,20 @@ export function useRemoveSummonFromCollection() {
}))
}
/**
* Remove multiple summons from collection in a single batch
*/
export function useBulkRemoveSummonsFromCollection() {
const queryClient = useQueryClient()
return createMutation(() => ({
mutationFn: (ids: string[]) => collectionAdapter.removeSummonsBatch(ids),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: collectionKeys.summons() })
}
}))
}
// ============================================================================
// Job Accessory Mutations
// ============================================================================