A tool to help Granblue Fantasy players create and share teams and strategies.
Find a file
Justin Edmund f457343e26
Complete TanStack Query v6 migration (#445)
## Overview

Complete migration from service layer to TanStack Query v6 with
mutations, queries, and automatic cache management.

## What Was Completed

### Phase 1: Entity Queries & Database Pages 
- Created `entity.queries.ts` with query options for weapons,
characters, and summons
- Migrated all database detail pages to use TanStack Query with
`withInitialData()` pattern
- SSR with client-side hydration working correctly

### Phase 2: Server Load Cleanup 
- Removed PartyService dependency from teams detail server load
- Server loads now use adapters directly instead of service layer
- Cleaner separation of concerns

### Phase 3: Party.svelte Refactoring 
- Removed all PartyService, GridService, and ConflictService
dependencies
- Migrated to TanStack Query mutations for all operations:
  - Grid operations: create, update, delete, swap, move
  - Party operations: update, delete, remix, favorite, unfavorite
- Added swap/move mutations for drag-and-drop operations
- Automatic cache invalidation and query refetching

### Phase 4: Service Layer Removal 
- Deleted all service layer files (~1,345 lines removed):
  - `party.service.ts` (620 lines)
  - `grid.service.ts` (450 lines)
  - `conflict.service.ts` (120 lines)
  - `gridOperations.ts` (unused utility)
- Deleted empty `services/` directory
- Created utility functions for cross-cutting concerns:
  - `localId.ts`: Anonymous user local ID management
  - `editKeys.ts`: Edit key management for anonymous editing
  - `party-context.ts`: Extracted PartyContext type

### Phase 5: /teams/new Migration 
- Migrated party creation wizard to use TanStack Query mutations
- Replaced all direct adapter calls with mutations (7 locations)
- Maintains existing behavior and flow
- Automatic cache invalidation for newly created parties

## Benefits

### Performance
- Automatic request deduplication
- Better cache utilization across pages
- Background refetching for fresh data
- Optimistic updates for instant UI feedback

### Developer Experience
- Single source of truth for data fetching
- Consistent patterns across entire app
- Query devtools for debugging
- Less boilerplate code

### Code Quality
- ~1,088 net lines removed
- Simpler mental model (no service layer)
- Better TypeScript inference
- Easier to test

### Architecture
- **100% TanStack Query coverage** - no service layer, no direct adapter
calls
- Clear separation: UI ← Queries/Mutations ← Adapters ← API
- Automatic cache management
- Consistent mutation patterns everywhere

## Testing

All features verified:
- Party creation (anonymous & authenticated)
- Grid operations (add, remove, update, swap, move)
- Party operations (update, delete, remix, favorite)
- Cache invalidation across tabs
- Error handling and rollback
- SSR with hydration

## Files Modified

### Created (3)
- `src/lib/types/party-context.ts`
- `src/lib/utils/editKeys.ts`
- `src/lib/utils/localId.ts`

### Deleted (4)
- `src/lib/services/party.service.ts`
- `src/lib/services/grid.service.ts`
- `src/lib/services/conflict.service.ts`
- `src/lib/utils/gridOperations.ts`

### Modified (13)
- `src/lib/api/mutations/grid.mutations.ts`
- `src/lib/components/grids/CharacterGrid.svelte`
- `src/lib/components/grids/SummonGrid.svelte`
- `src/lib/components/grids/WeaponGrid.svelte`
- `src/lib/components/party/Party.svelte`
- `src/routes/teams/new/+page.svelte`
- Database entity pages (characters, weapons, summons)
- Other supporting files

## Migration Complete

This PR completes the TanStack Query migration. The entire application
now uses TanStack Query v6 for all data fetching and mutations, with
zero remaining service layer code.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-29 22:32:15 -08:00
.storybook Init Svelte migration repo 2025-09-08 13:43:09 -07:00
.vscode Add project configuration files 2025-09-15 04:12:26 -07:00
messages add context menu ui components and i18n 2025-09-30 03:42:14 -07:00
project.inlang Add project configuration files 2025-09-15 04:12:26 -07:00
src Complete TanStack Query v6 migration (#445) 2025-11-29 22:32:15 -08:00
static Init Svelte migration repo 2025-09-08 13:43:09 -07:00
.gitignore Low-risk cleanup: unused imports, gitignore, auth types, test routes (#439) 2025-11-28 11:21:24 -08:00
.mcp.json Add project configuration files 2025-09-15 04:12:26 -07:00
.npmrc Init Svelte migration repo 2025-09-08 13:43:09 -07:00
.prettierignore Init Svelte migration repo 2025-09-08 13:43:09 -07:00
.prettierrc Update config files 2025-09-09 00:27:09 -07:00
CLAUDE.md remove barrel files and update imports 2025-09-29 23:37:37 -07:00
eslint.config.js Update config files 2025-09-09 00:27:09 -07:00
NEXT_SESSION_PROMPT.md docs: update NEXT_SESSION_PROMPT.md with current progress (161 errors remaining) 2025-11-28 21:25:11 +00:00
package.json feat: add TanStack Query devtools for development 2025-11-29 03:44:59 -08:00
pnpm-lock.yaml feat: add TanStack Query devtools for development 2025-11-29 03:44:59 -08:00
README.md Init Svelte migration repo 2025-09-08 13:43:09 -07:00
svelte.config.js fix: type errors in svelte-main branch (219 -> 191 errors) 2025-11-28 21:06:05 +00:00
TANSTACK_QUERY_MIGRATION_CONTINUATION.md feat: migrate components to TanStack Query v6 (Phase 2) (#442) 2025-11-29 01:11:24 -08:00
tsconfig.json refactor: remove exactOptionalPropertyTypes and fix import casing 2025-11-28 19:19:32 -08:00
TYPESCRIPT_IMPROVEMENTS.md refactor: consolidate Awakening type definition 2025-11-28 21:48:21 -08:00
vite.config.ts fix scss imports with modern compiler api 2025-09-16 01:35:05 -07:00
vitest-setup-client.ts Init Svelte migration repo 2025-09-08 13:43:09 -07:00
vitest.config.adapter.ts feat: implement base adapter with retry logic and caching 2025-09-19 23:03:36 -07:00

sv

Everything you need to build a Svelte project, powered by sv.

Creating a project

If you're seeing this, you've probably already done this step. Congrats!

# create a new project in the current directory
npx sv create

# create a new project in my-app
npx sv create my-app

Developing

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Building

To create a production version of your app:

npm run build

You can preview the production build with npm run preview.

To deploy your app, you may need to install an adapter for your target environment.