From 100f506c44330e592e498d8cb07877834db37bb6 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 3 Dec 2025 18:11:01 -0800 Subject: [PATCH] move add artifact button to header as elemental button --- .../sidebar/AddArtifactSidebar.svelte | 61 +++++++++++-------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/lib/components/sidebar/AddArtifactSidebar.svelte b/src/lib/components/sidebar/AddArtifactSidebar.svelte index f0095b62..48f4e734 100644 --- a/src/lib/components/sidebar/AddArtifactSidebar.svelte +++ b/src/lib/components/sidebar/AddArtifactSidebar.svelte @@ -11,19 +11,20 @@ * 4. Configure level, nickname * 5. Configure skills (for standard artifacts only, uses pane stack) */ + import { onMount, untrack } from 'svelte' import type { Artifact, ArtifactSkill, ArtifactSkillInstance, CollectionArtifactInput } from '$lib/types/api/artifact' import { isQuirkArtifact, getSkillGroupForSlot } from '$lib/types/api/artifact' import { createQuery } from '@tanstack/svelte-query' import { artifactQueries } from '$lib/api/queries/artifact.queries' import { useCreateCollectionArtifact } from '$lib/api/mutations/artifact.mutations' - import { usePaneStack, type PaneConfig } from '$lib/stores/paneStack.svelte' + import { usePaneStack, type PaneConfig, type ElementType } from '$lib/stores/paneStack.svelte' + import { sidebar } from '$lib/stores/sidebar.svelte' import DetailsSection from '$lib/components/sidebar/details/DetailsSection.svelte' import DetailRow from '$lib/components/sidebar/details/DetailRow.svelte' import Select from '$lib/components/ui/Select.svelte' import Input from '$lib/components/ui/Input.svelte' import ArtifactSkillRow from '$lib/components/artifact/ArtifactSkillRow.svelte' import ArtifactModifierList from '$lib/components/artifact/ArtifactModifierList.svelte' - import Button from '$lib/components/ui/Button.svelte' interface Props { /** Callback when artifact is created successfully */ @@ -206,6 +207,17 @@ selectedArtifactId !== undefined ) + // Convert numeric element to ElementType string for button styling + const elementTypeMap: Record = { + 1: 'wind', + 2: 'fire', + 3: 'water', + 4: 'earth', + 5: 'dark', + 6: 'light' + } + const elementType = $derived(element !== undefined ? elementTypeMap[element] : undefined) + // Handle save async function handleSave() { if (!selectedArtifactId || !isValid || element === undefined) return @@ -230,6 +242,29 @@ } }) } + + // Update the header action button based on form validity and element + function updateHeaderAction() { + if (isValid && !createMutation.isPending) { + sidebar.setAction(handleSave, 'Add', elementType) + } else { + sidebar.clearAction() + } + } + + // Set up header action on mount and when validity/element changes + onMount(() => { + updateHeaderAction() + return () => sidebar.clearAction() + }) + + // Reactively update action when form state changes + $effect(() => { + // Access reactive dependencies + const _ = [isValid, element, createMutation.isPending] + // Use untrack to avoid infinite loop when calling sidebar methods + untrack(() => updateHeaderAction()) + })
@@ -321,16 +356,6 @@ {/if}
-