diff --git a/src/lib/api/mutations/grid.mutations.ts b/src/lib/api/mutations/grid.mutations.ts index edb38f78..70ca02cf 100644 --- a/src/lib/api/mutations/grid.mutations.ts +++ b/src/lib/api/mutations/grid.mutations.ts @@ -14,7 +14,8 @@ import { type CreateGridCharacterParams, type CreateGridSummonParams, type UpdateUncapParams, - type ResolveConflictParams + type ResolveConflictParams, + type SwapPositionsParams } from '$lib/api/adapters/grid.adapter' import { partyKeys } from '$lib/api/queries/party.queries' import type { Party, GridWeapon, GridCharacter, GridSummon } from '$lib/types/api/party' @@ -214,6 +215,23 @@ export function useResolveWeaponConflict() { })) } +/** + * Swap weapon positions mutation + * + * Swaps the positions of two weapons in the grid. + */ +export function useSwapWeapons() { + const queryClient = useQueryClient() + + return createMutation(() => ({ + mutationFn: (params: SwapPositionsParams & { partyShortcode: string }) => + gridAdapter.swapWeapons(params), + onSuccess: (_data, { partyShortcode }) => { + queryClient.invalidateQueries({ queryKey: partyKeys.detail(partyShortcode) }) + } + })) +} + // ============================================================================ // Character Mutations // ============================================================================ @@ -374,6 +392,23 @@ export function useResolveCharacterConflict() { })) } +/** + * Swap character positions mutation + * + * Swaps the positions of two characters in the grid. + */ +export function useSwapCharacters() { + const queryClient = useQueryClient() + + return createMutation(() => ({ + mutationFn: (params: SwapPositionsParams & { partyShortcode: string }) => + gridAdapter.swapCharacters(params), + onSuccess: (_data, { partyShortcode }) => { + queryClient.invalidateQueries({ queryKey: partyKeys.detail(partyShortcode) }) + } + })) +} + // ============================================================================ // Summon Mutations // ============================================================================ @@ -566,3 +601,20 @@ export function useUpdateQuickSummon() { } })) } + +/** + * Swap summon positions mutation + * + * Swaps the positions of two summons in the grid. + */ +export function useSwapSummons() { + const queryClient = useQueryClient() + + return createMutation(() => ({ + mutationFn: (params: SwapPositionsParams & { partyShortcode: string }) => + gridAdapter.swapSummons(params), + onSuccess: (_data, { partyShortcode }) => { + queryClient.invalidateQueries({ queryKey: partyKeys.detail(partyShortcode) }) + } + })) +} diff --git a/src/lib/components/grids/CharacterGrid.svelte b/src/lib/components/grids/CharacterGrid.svelte index c98b9de4..fee9db0a 100644 --- a/src/lib/components/grids/CharacterGrid.svelte +++ b/src/lib/components/grids/CharacterGrid.svelte @@ -4,7 +4,7 @@ import type { GridCharacter } from '$lib/types/api/party' import type { Job } from '$lib/types/api/entities' import { getContext } from 'svelte' - import type { PartyContext } from '$lib/services/party.service' + import type { PartyContext } from '$lib/types/party-context' import type { DragDropContext } from '$lib/composables/drag-drop.svelte' import DraggableItem from '$lib/components/dnd/DraggableItem.svelte' import DropZone from '$lib/components/dnd/DropZone.svelte' diff --git a/src/lib/components/grids/SummonGrid.svelte b/src/lib/components/grids/SummonGrid.svelte index 3cfbb771..3ed8ffa6 100644 --- a/src/lib/components/grids/SummonGrid.svelte +++ b/src/lib/components/grids/SummonGrid.svelte @@ -3,7 +3,7 @@