migrate /teams/new to use TanStack Query mutations
- replace partyAdapter.create() with useCreateParty mutation - replace all gridAdapter.create*() calls with mutations - automatic cache invalidation now works across the app - completes TanStack Query migration (100% coverage)
This commit is contained in:
parent
6d0257df26
commit
ddd33d1e53
1 changed files with 21 additions and 8 deletions
|
|
@ -11,6 +11,14 @@
|
||||||
import type { SearchResult } from '$lib/api/adapters'
|
import type { SearchResult } from '$lib/api/adapters'
|
||||||
import { partyAdapter, gridAdapter } from '$lib/api/adapters'
|
import { partyAdapter, gridAdapter } from '$lib/api/adapters'
|
||||||
import { getLocalId } from '$lib/utils/localId'
|
import { getLocalId } from '$lib/utils/localId'
|
||||||
|
|
||||||
|
// TanStack Query mutations
|
||||||
|
import { useCreateParty } from '$lib/api/mutations/party.mutations'
|
||||||
|
import {
|
||||||
|
useCreateGridWeapon,
|
||||||
|
useCreateGridCharacter,
|
||||||
|
useCreateGridSummon
|
||||||
|
} from '$lib/api/mutations/grid.mutations'
|
||||||
import { Dialog } from 'bits-ui'
|
import { Dialog } from 'bits-ui'
|
||||||
import { replaceState } from '$app/navigation'
|
import { replaceState } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
|
@ -75,6 +83,11 @@
|
||||||
let errorMessage = $state('')
|
let errorMessage = $state('')
|
||||||
let errorDetails = $state<string[]>([])
|
let errorDetails = $state<string[]>([])
|
||||||
|
|
||||||
|
// TanStack Query mutations
|
||||||
|
const createPartyMutation = useCreateParty()
|
||||||
|
const createWeaponMutation = useCreateGridWeapon()
|
||||||
|
const createCharacterMutation = useCreateGridCharacter()
|
||||||
|
const createSummonMutation = useCreateGridSummon()
|
||||||
|
|
||||||
// Calculate if grids are full
|
// Calculate if grids are full
|
||||||
let isWeaponGridFull = $derived(weapons.length >= 10) // 1 mainhand + 9 grid slots
|
let isWeaponGridFull = $derived(weapons.length >= 10) // 1 mainhand + 9 grid slots
|
||||||
|
|
@ -115,8 +128,8 @@
|
||||||
partyPayload.localId = getLocalId()
|
partyPayload.localId = getLocalId()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create party using the party adapter
|
// Create party using mutation
|
||||||
const createdParty = await partyAdapter.create(partyPayload)
|
const createdParty = await createPartyMutation.mutateAsync(partyPayload)
|
||||||
console.log('Party created:', createdParty)
|
console.log('Party created:', createdParty)
|
||||||
|
|
||||||
// The adapter returns the party directly
|
// The adapter returns the party directly
|
||||||
|
|
@ -136,7 +149,7 @@
|
||||||
if (activeTab === GridType.Weapon) {
|
if (activeTab === GridType.Weapon) {
|
||||||
// Use selectedSlot if available, otherwise default to mainhand
|
// Use selectedSlot if available, otherwise default to mainhand
|
||||||
if (selectedSlot === null) position = -1
|
if (selectedSlot === null) position = -1
|
||||||
const addResult = await gridAdapter.createWeapon({
|
const addResult = await createWeaponMutation.mutateAsync({
|
||||||
partyId,
|
partyId,
|
||||||
weaponId: firstItem.granblueId,
|
weaponId: firstItem.granblueId,
|
||||||
position,
|
position,
|
||||||
|
|
@ -159,7 +172,7 @@
|
||||||
} else if (activeTab === GridType.Summon) {
|
} else if (activeTab === GridType.Summon) {
|
||||||
// Use selectedSlot if available, otherwise default to main summon
|
// Use selectedSlot if available, otherwise default to main summon
|
||||||
if (selectedSlot === null) position = -1
|
if (selectedSlot === null) position = -1
|
||||||
const addResult = await gridAdapter.createSummon({
|
const addResult = await createSummonMutation.mutateAsync({
|
||||||
partyId,
|
partyId,
|
||||||
summonId: firstItem.granblueId,
|
summonId: firstItem.granblueId,
|
||||||
position,
|
position,
|
||||||
|
|
@ -184,7 +197,7 @@
|
||||||
} else if (activeTab === GridType.Character) {
|
} else if (activeTab === GridType.Character) {
|
||||||
// Use selectedSlot if available, otherwise default to first slot
|
// Use selectedSlot if available, otherwise default to first slot
|
||||||
if (selectedSlot === null) position = 0
|
if (selectedSlot === null) position = 0
|
||||||
const addResult = await gridAdapter.createCharacter({
|
const addResult = await createCharacterMutation.mutateAsync({
|
||||||
partyId,
|
partyId,
|
||||||
characterId: firstItem.granblueId,
|
characterId: firstItem.granblueId,
|
||||||
position
|
position
|
||||||
|
|
@ -281,7 +294,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add weapon via API
|
// Add weapon via API
|
||||||
const response = await gridAdapter.createWeapon({
|
const response = await createWeaponMutation.mutateAsync({
|
||||||
partyId,
|
partyId,
|
||||||
weaponId: item.granblueId,
|
weaponId: item.granblueId,
|
||||||
position,
|
position,
|
||||||
|
|
@ -313,7 +326,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add summon via API
|
// Add summon via API
|
||||||
const response = await gridAdapter.createSummon({
|
const response = await createSummonMutation.mutateAsync({
|
||||||
partyId,
|
partyId,
|
||||||
summonId: item.granblueId,
|
summonId: item.granblueId,
|
||||||
position,
|
position,
|
||||||
|
|
@ -347,7 +360,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add character via API
|
// Add character via API
|
||||||
const response = await gridAdapter.createCharacter({
|
const response = await createCharacterMutation.mutateAsync({
|
||||||
partyId,
|
partyId,
|
||||||
characterId: item.granblueId,
|
characterId: item.granblueId,
|
||||||
position
|
position
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue