From 8bca8f85d560f128cd37beea52338fe25d20dd79 Mon Sep 17 00:00:00 2001 From: n8n-gitea Date: Tue, 9 Jun 2026 19:08:49 +0200 Subject: [PATCH] fix: persist CraftingTab sub-tab selection across tab navigation - Add activeCraftingSubTab state + setActiveCraftingSubTab action to craftingStore (persisted to localStorage via zustand persist middleware) - Add CraftingAttunement type to craftingStore.types and re-export from stores/index.ts barrel - Update CraftingTab.tsx to read/write active sub-tab from store instead of local useState, so selection survives component remount - Add default 'fabricator' value in craft-initial-state.ts --- docs/circular-deps.txt | 2 +- docs/dependency-graph.json | 2 +- src/components/game/tabs/CraftingTab.tsx | 8 ++++---- src/lib/game/stores/crafting-initial-state.ts | 1 + src/lib/game/stores/craftingStore.ts | 3 +++ src/lib/game/stores/craftingStore.types.ts | 4 ++++ src/lib/game/stores/index.ts | 2 +- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/circular-deps.txt b/docs/circular-deps.txt index 21e8a44..519effd 100644 --- a/docs/circular-deps.txt +++ b/docs/circular-deps.txt @@ -1,5 +1,5 @@ # Circular Dependencies -Generated: 2026-06-09T13:31:30.036Z +Generated: 2026-06-09T16:48:20.172Z Found: 2 circular chain(s) — these MUST be fixed before modifying involved files. 1. 1) stores/golem-combat-actions.ts > stores/golem-combat-helpers.ts diff --git a/docs/dependency-graph.json b/docs/dependency-graph.json index 6b95833..a5a408a 100644 --- a/docs/dependency-graph.json +++ b/docs/dependency-graph.json @@ -1,6 +1,6 @@ { "_meta": { - "generated": "2026-06-09T13:31:28.048Z", + "generated": "2026-06-09T16:48:18.218Z", "description": "Import dependency graph for src/lib/game. Keys are files, values are arrays of files they import.", "usage": "To find what a file affects, search for its path in the VALUES. To find what a file depends on, look at its KEY entry." }, diff --git a/src/components/game/tabs/CraftingTab.tsx b/src/components/game/tabs/CraftingTab.tsx index 83e30d9..cd8833b 100644 --- a/src/components/game/tabs/CraftingTab.tsx +++ b/src/components/game/tabs/CraftingTab.tsx @@ -1,14 +1,13 @@ 'use client'; -import { useState } from 'react'; import clsx from 'clsx'; import { Hammer, Sparkles } from 'lucide-react'; import { DebugName } from '@/components/game/debug/debug-context'; +import { useCraftingStore } from '@/lib/game/stores/craftingStore'; +import type { CraftingAttunement } from '@/lib/game/stores/craftingStore.types'; import { FabricatorSubTab } from './CraftingTab/FabricatorSubTab'; import { EnchanterSubTab } from './CraftingTab/EnchanterSubTab'; -type CraftingAttunement = 'fabricator' | 'enchanter'; - interface CraftingSubTab { key: CraftingAttunement; label: string; @@ -21,7 +20,8 @@ const CRAFTING_SUB_TABS: CraftingSubTab[] = [ ]; export function CraftingTab() { - const [activeSubTab, setActiveSubTab] = useState('fabricator'); + const activeSubTab = useCraftingStore((s) => s.activeCraftingSubTab); + const setActiveSubTab = useCraftingStore((s) => s.setActiveCraftingSubTab); return ( diff --git a/src/lib/game/stores/crafting-initial-state.ts b/src/lib/game/stores/crafting-initial-state.ts index 879cc34..f337507 100644 --- a/src/lib/game/stores/crafting-initial-state.ts +++ b/src/lib/game/stores/crafting-initial-state.ts @@ -34,6 +34,7 @@ export function createDefaultCraftingState(): CraftingState { selectedEquipmentInstance: null, }, lastError: null, + activeCraftingSubTab: 'fabricator', }; } diff --git a/src/lib/game/stores/craftingStore.ts b/src/lib/game/stores/craftingStore.ts index f281cad..efa9a3d 100644 --- a/src/lib/game/stores/craftingStore.ts +++ b/src/lib/game/stores/craftingStore.ts @@ -285,6 +285,8 @@ export const useCraftingStore = create()( clearLastError: () => set({ lastError: null }), + setActiveCraftingSubTab: (tab) => set({ activeCraftingSubTab: tab }), + unlockEffects: (effectIds: string[]) => { set((state) => { const existing = new Set(state.unlockedEffects); @@ -343,6 +345,7 @@ export const useCraftingStore = create()( lootInventory: state.lootInventory, enchantmentSelection: state.enchantmentSelection, lastError: state.lastError, + activeCraftingSubTab: state.activeCraftingSubTab, }), } ) diff --git a/src/lib/game/stores/craftingStore.types.ts b/src/lib/game/stores/craftingStore.types.ts index 23f3c4e..f99a1e7 100644 --- a/src/lib/game/stores/craftingStore.types.ts +++ b/src/lib/game/stores/craftingStore.types.ts @@ -16,6 +16,8 @@ export interface CraftingError { timestamp: number; } +export type CraftingAttunement = 'fabricator' | 'enchanter'; + export interface CraftingState { designProgress: DesignProgress | null; designProgress2: DesignProgress | null; @@ -39,6 +41,7 @@ export interface CraftingState { selectedEquipmentInstance: string | null; }; lastError: CraftingError | null; + activeCraftingSubTab: CraftingAttunement; } export interface CraftingActions { @@ -47,6 +50,7 @@ export interface CraftingActions { setPreparationProgress: (progress: PreparationProgress | null) => void; setApplicationProgress: (progress: ApplicationProgress | null) => void; setEquipmentCraftingProgress: (progress: EquipmentCraftingProgress | null) => void; + setActiveCraftingSubTab: (tab: CraftingAttunement) => void; startDesigningEnchantment: (name: string, equipmentTypeId: string, effects: DesignEffect[]) => boolean; cancelDesign: (slot?: 1 | 2) => void; saveDesign: (design: EnchantmentDesign) => void; diff --git a/src/lib/game/stores/index.ts b/src/lib/game/stores/index.ts index 95d4262..e387591 100755 --- a/src/lib/game/stores/index.ts +++ b/src/lib/game/stores/index.ts @@ -15,7 +15,7 @@ export { useCombatStore, makeInitialSpells } from './combatStore'; export type { CombatState, CombatActions, CombatStore } from './combat-state.types'; export { useCraftingStore } from './craftingStore'; -export type { CraftingState, CraftingActions } from './craftingStore.types'; +export type { CraftingState, CraftingActions, CraftingStore, CraftingAttunement } from './craftingStore.types'; export { useAttunementStore } from './attunementStore'; export type { AttunementStoreState } from './attunementStore';