remove ConflictService and unused gridStateUpdater
- remove ConflictService import (not used) - delete gridStateUpdater.ts (no longer imported) - add TODO comments for remaining service dependencies - keep GridService/PartyService for swap/move operations (needs future work)
This commit is contained in:
parent
b9db4433d5
commit
e34ea379bd
2 changed files with 4 additions and 143 deletions
|
|
@ -15,10 +15,10 @@
|
||||||
useUpdateSummonUncap
|
useUpdateSummonUncap
|
||||||
} from '$lib/api/mutations/grid.mutations'
|
} from '$lib/api/mutations/grid.mutations'
|
||||||
|
|
||||||
// Services (to be removed in Phase 4)
|
// Legacy services - kept only for swap/move operations and edit keys
|
||||||
|
// TODO: Remove once swap/move mutations are implemented
|
||||||
import { PartyService } from '$lib/services/party.service'
|
import { PartyService } from '$lib/services/party.service'
|
||||||
import { GridService } from '$lib/services/grid.service'
|
import { GridService } from '$lib/services/grid.service'
|
||||||
import { ConflictService } from '$lib/services/conflict.service'
|
|
||||||
|
|
||||||
import { createDragDropContext, type DragOperation } from '$lib/composables/drag-drop.svelte'
|
import { createDragDropContext, type DragOperation } from '$lib/composables/drag-drop.svelte'
|
||||||
import WeaponGrid from '$lib/components/grids/WeaponGrid.svelte'
|
import WeaponGrid from '$lib/components/grids/WeaponGrid.svelte'
|
||||||
|
|
@ -74,10 +74,9 @@
|
||||||
let editDialogOpen = $state(false)
|
let editDialogOpen = $state(false)
|
||||||
let editingTitle = $state('')
|
let editingTitle = $state('')
|
||||||
|
|
||||||
// Services (Phase 4: to be removed)
|
// Legacy services - only for swap/move and edit keys
|
||||||
const partyService = new PartyService()
|
const partyService = new PartyService()
|
||||||
const gridService = new GridService()
|
const gridService = new GridService()
|
||||||
const conflictService = new ConflictService()
|
|
||||||
|
|
||||||
// TanStack Query mutations
|
// TanStack Query mutations
|
||||||
const deleteWeapon = useDeleteGridWeapon()
|
const deleteWeapon = useDeleteGridWeapon()
|
||||||
|
|
@ -683,8 +682,7 @@
|
||||||
getEditKey: () => editKey,
|
getEditKey: () => editKey,
|
||||||
services: {
|
services: {
|
||||||
partyService,
|
partyService,
|
||||||
gridService: clientGridService, // Use client-side wrapper
|
gridService: clientGridService // Uses TanStack Query mutations
|
||||||
conflictService
|
|
||||||
},
|
},
|
||||||
openPicker: (opts: {
|
openPicker: (opts: {
|
||||||
type: 'weapon' | 'summon' | 'character'
|
type: 'weapon' | 'summon' | 'character'
|
||||||
|
|
|
||||||
|
|
@ -1,137 +0,0 @@
|
||||||
/**
|
|
||||||
* Grid state update utilities
|
|
||||||
* Handles optimistic updates for uncap levels and other grid item properties
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { Party } from '$lib/types/api/party'
|
|
||||||
import type { GridService } from '$lib/services/grid.service'
|
|
||||||
import type { GridItemType, GridCollection } from './gridOperations'
|
|
||||||
import { getCollectionKey } from './gridOperations'
|
|
||||||
|
|
||||||
export interface UncapUpdateParams {
|
|
||||||
gridItemId: string
|
|
||||||
uncapLevel?: number
|
|
||||||
transcendenceStep?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic function to update uncap levels for any grid item type
|
|
||||||
* Replaces updateCharacterUncap, updateWeaponUncap, updateSummonUncap
|
|
||||||
*
|
|
||||||
* @param itemType - Type of grid item (character, weapon, or summon)
|
|
||||||
* @param params - Uncap update parameters
|
|
||||||
* @param partyId - Party UUID
|
|
||||||
* @param currentParty - Current party state
|
|
||||||
* @param editKey - Optional edit key for authorization
|
|
||||||
* @param gridService - Grid service instance
|
|
||||||
* @returns Updated party with modified uncap levels
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```typescript
|
|
||||||
* const updated = await updateGridItemUncap(
|
|
||||||
* 'weapon',
|
|
||||||
* { gridItemId: 'abc123', uncapLevel: 4, transcendenceStep: 1 },
|
|
||||||
* party.id,
|
|
||||||
* party,
|
|
||||||
* editKey,
|
|
||||||
* gridService
|
|
||||||
* )
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export async function updateGridItemUncap(
|
|
||||||
itemType: GridItemType,
|
|
||||||
params: UncapUpdateParams,
|
|
||||||
partyId: string,
|
|
||||||
currentParty: Party,
|
|
||||||
editKey: string | undefined,
|
|
||||||
gridService: GridService
|
|
||||||
): Promise<Party> {
|
|
||||||
// Get configuration for this item type
|
|
||||||
const config = getGridItemConfig(itemType)
|
|
||||||
|
|
||||||
// Call appropriate service method
|
|
||||||
const response = await config.updateMethod(
|
|
||||||
gridService,
|
|
||||||
partyId,
|
|
||||||
params.gridItemId,
|
|
||||||
params.uncapLevel,
|
|
||||||
params.transcendenceStep,
|
|
||||||
editKey
|
|
||||||
)
|
|
||||||
|
|
||||||
// Extract updated item from response (handle both camelCase and snake_case)
|
|
||||||
const updatedItem = response[config.responseKey] || response[config.snakeCaseKey]
|
|
||||||
if (!updatedItem) return currentParty
|
|
||||||
|
|
||||||
// Update party state optimistically
|
|
||||||
return mergeUpdatedGridItem(currentParty, config.collectionKey, params.gridItemId, {
|
|
||||||
uncapLevel: updatedItem.uncapLevel ?? updatedItem.uncap_level,
|
|
||||||
transcendenceStep: updatedItem.transcendenceStep ?? updatedItem.transcendence_step
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration map for grid item types
|
|
||||||
*/
|
|
||||||
function getGridItemConfig(itemType: GridItemType) {
|
|
||||||
const configs = {
|
|
||||||
character: {
|
|
||||||
updateMethod: (gs: GridService, ...args: any[]) => gs.updateCharacterUncap(...args),
|
|
||||||
responseKey: 'gridCharacter',
|
|
||||||
snakeCaseKey: 'grid_character',
|
|
||||||
collectionKey: 'characters' as GridCollection
|
|
||||||
},
|
|
||||||
weapon: {
|
|
||||||
updateMethod: (gs: GridService, ...args: any[]) => gs.updateWeaponUncap(...args),
|
|
||||||
responseKey: 'gridWeapon',
|
|
||||||
snakeCaseKey: 'grid_weapon',
|
|
||||||
collectionKey: 'weapons' as GridCollection
|
|
||||||
},
|
|
||||||
summon: {
|
|
||||||
updateMethod: (gs: GridService, ...args: any[]) => gs.updateSummonUncap(...args),
|
|
||||||
responseKey: 'gridSummon',
|
|
||||||
snakeCaseKey: 'grid_summon',
|
|
||||||
collectionKey: 'summons' as GridCollection
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return configs[itemType]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges updates into a grid item within party state
|
|
||||||
* Preserves immutability by creating new objects
|
|
||||||
*
|
|
||||||
* @param party - Current party state
|
|
||||||
* @param collection - Collection key (characters, weapons, or summons)
|
|
||||||
* @param itemId - Grid item ID to update
|
|
||||||
* @param updates - Fields to update
|
|
||||||
* @returns New party object with updates applied
|
|
||||||
*/
|
|
||||||
function mergeUpdatedGridItem(
|
|
||||||
party: Party,
|
|
||||||
collection: GridCollection,
|
|
||||||
itemId: string,
|
|
||||||
updates: any
|
|
||||||
): Party {
|
|
||||||
const updatedParty = { ...party }
|
|
||||||
const items = updatedParty[collection]
|
|
||||||
|
|
||||||
if (!items) return party
|
|
||||||
|
|
||||||
const itemIndex = items.findIndex((item: any) => item.id === itemId)
|
|
||||||
if (itemIndex === -1) return party
|
|
||||||
|
|
||||||
const existingItem = items[itemIndex]
|
|
||||||
if (!existingItem) return party
|
|
||||||
|
|
||||||
// Merge updates while preserving essential properties
|
|
||||||
items[itemIndex] = {
|
|
||||||
...existingItem,
|
|
||||||
...updates,
|
|
||||||
id: existingItem.id,
|
|
||||||
position: existingItem.position
|
|
||||||
}
|
|
||||||
|
|
||||||
return updatedParty
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue