From cc46a695d51350fe0d3506d61173d9b11bb76a85 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 16 Sep 2025 20:09:36 -0700 Subject: [PATCH] use visual segmented control in party views --- src/lib/components/party/Party.svelte | 116 ++++++-------------------- src/routes/teams/new/+page.svelte | 95 +++++++-------------- 2 files changed, 58 insertions(+), 153 deletions(-) diff --git a/src/lib/components/party/Party.svelte b/src/lib/components/party/Party.svelte index 9205a966..a17ccb27 100644 --- a/src/lib/components/party/Party.svelte +++ b/src/lib/components/party/Party.svelte @@ -10,7 +10,9 @@ import SummonGrid from '$lib/components/grids/SummonGrid.svelte' import CharacterGrid from '$lib/components/grids/CharacterGrid.svelte' import SearchSidebar from '$lib/components/panels/SearchSidebar.svelte' + import PartySegmentedControl from '$lib/components/party/PartySegmentedControl.svelte' import type { SearchResult } from '$lib/api/resources/search' + import { GridType } from '$lib/types/enums' import Dialog from '$lib/components/ui/Dialog.svelte' interface Props { @@ -38,7 +40,7 @@ ? initial : defaultParty ) - let activeTab = $state<'weapons' | 'summons' | 'characters'>('weapons') + let activeTab = $state(GridType.Weapon) let loading = $state(false) let error = $state(null) let pickerOpen = $state(false) @@ -212,20 +214,13 @@ return result.canEdit }) - // Tab configuration - use function to avoid state capture - const tabs = $derived([ - { key: 'weapons' as const, label: 'Weapons', count: (party?.weapons ?? []).length }, - { key: 'summons' as const, label: 'Summons', count: (party?.summons ?? []).length }, - { key: 'characters' as const, label: 'Characters', count: (party?.characters ?? []).length } - ]) - // Derived elements for character image logic const mainWeapon = $derived(() => (party?.weapons ?? []).find(w => w?.mainhand || w?.position === -1)) const mainWeaponElement = $derived(() => mainWeapon?.element ?? mainWeapon?.weapon?.element) const partyElement = $derived(() => party?.element) - function selectTab(key: typeof tabs[number]['key']) { - activeTab = key + function handleTabChange(tab: GridType) { + activeTab = tab } // Edit dialog functions @@ -334,16 +329,16 @@ let targetSlot = selectedSlot // Call appropriate API based on current tab - if (activeTab === 'weapons') { + if (activeTab === GridType.Weapon) { await apiClient.addWeapon(party.id, item.granblue_id, targetSlot, { mainhand: targetSlot === -1 }) - } else if (activeTab === 'summons') { + } else if (activeTab === GridType.Summon) { await apiClient.addSummon(party.id, item.granblue_id, targetSlot, { main: targetSlot === -1, friend: targetSlot === 6 }) - } else if (activeTab === 'characters') { + } else if (activeTab === GridType.Character) { await apiClient.addCharacter(party.id, item.granblue_id, targetSlot) } @@ -354,7 +349,7 @@ // Find next empty slot for continuous adding let nextEmptySlot = -999 // sentinel value meaning no empty slot found - if (activeTab === 'weapons') { + if (activeTab === GridType.Weapon) { // Check mainhand first (position -1) if (!party.weapons.find(w => w.position === -1 || w.mainhand)) { nextEmptySlot = -1 @@ -367,7 +362,7 @@ } } } - } else if (activeTab === 'summons') { + } else if (activeTab === GridType.Summon) { // Check main summon first (position -1) if (!party.summons.find(s => s.position === -1 || s.main)) { nextEmptySlot = -1 @@ -384,7 +379,7 @@ nextEmptySlot = 6 } } - } else if (activeTab === 'characters') { + } else if (activeTab === GridType.Character) { // Check character slots 0-4 for (let i = 0; i < 5; i++) { if (!party.characters.find(c => c.position === i)) { @@ -471,8 +466,8 @@ openPicker: (opts: { type: 'weapon' | 'summon' | 'character'; position: number; item?: any }) => { if (!canEdit()) return selectedSlot = opts.position - activeTab = opts.type === 'weapon' ? 'weapons' : - opts.type === 'summon' ? 'summons' : 'characters' + activeTab = opts.type === 'weapon' ? GridType.Weapon : + opts.type === 'summon' ? GridType.Summon : GridType.Character pickerTitle = `Search ${opts.type}s` pickerOpen = true } @@ -549,21 +544,12 @@ {/if} - + {#if error}