diff --git a/src/lib/components/sidebar/SearchContent.svelte b/src/lib/components/sidebar/SearchContent.svelte new file mode 100644 index 00000000..20e27f0e --- /dev/null +++ b/src/lib/components/sidebar/SearchContent.svelte @@ -0,0 +1,510 @@ + + + + +
+
+ +
+ +
+ +
+ +
+ {#each elements as element} + + {/each} +
+
+ + +
+ +
+ {#each rarities as rarity} + + {/each} +
+
+ + + {#if type === 'weapon'} +
+ +
+ {#each proficiencies as prof} + + {/each} +
+
+ {/if} +
+ + +
+ {#if isLoading} +
Searching...
+ {:else if searchResults.length > 0} +
    + {#each searchResults as item (item.id)} +
  • + +
  • + {/each} +
+ + {#if totalPages > 1} + + {/if} + {:else if searchQuery.length > 0} +
No results found
+ {:else} +
Start typing to search
+ {/if} +
+
+ + \ No newline at end of file diff --git a/src/lib/features/search/openSearchSidebar.svelte.ts b/src/lib/features/search/openSearchSidebar.svelte.ts new file mode 100644 index 00000000..63844290 --- /dev/null +++ b/src/lib/features/search/openSearchSidebar.svelte.ts @@ -0,0 +1,25 @@ +import { sidebar } from '$lib/stores/sidebar.svelte' +import SearchContent from '$lib/components/sidebar/SearchContent.svelte' +import type { SearchResult } from '$lib/api/adapters/search.adapter' + +interface SearchSidebarOptions { + type: 'weapon' | 'character' | 'summon' + onAddItems?: (items: SearchResult[]) => void + canAddMore?: boolean +} + +export function openSearchSidebar(options: SearchSidebarOptions) { + const { type, onAddItems, canAddMore = true } = options + + // Open the sidebar with the search component + const title = `Search ${type.charAt(0).toUpperCase() + type.slice(1)}s` + sidebar.openWithComponent(title, SearchContent, { + type, + onAddItems, + canAddMore + }) +} + +export function closeSearchSidebar() { + sidebar.close() +} \ No newline at end of file diff --git a/src/lib/stores/sidebar.svelte.ts b/src/lib/stores/sidebar.svelte.ts index 5c38830b..7461844b 100644 --- a/src/lib/stores/sidebar.svelte.ts +++ b/src/lib/stores/sidebar.svelte.ts @@ -1,4 +1,4 @@ -import type { Snippet } from 'svelte' +import type { Snippet, Component } from 'svelte' // Standard sidebar width export const SIDEBAR_WIDTH = '420px' @@ -7,19 +7,33 @@ interface SidebarState { open: boolean title?: string content?: Snippet + component?: Component + componentProps?: Record } class SidebarStore { state = $state({ open: false, title: undefined, - content: undefined + content: undefined, + component: undefined, + componentProps: undefined }) open(title?: string, content?: Snippet) { this.state.open = true this.state.title = title this.state.content = content + this.state.component = undefined + this.state.componentProps = undefined + } + + openWithComponent(title: string, component: Component, props?: Record) { + this.state.open = true + this.state.title = title + this.state.component = component + this.state.componentProps = props + this.state.content = undefined } close() { @@ -28,6 +42,8 @@ class SidebarStore { setTimeout(() => { this.state.title = undefined this.state.content = undefined + this.state.component = undefined + this.state.componentProps = undefined }, 300) } @@ -50,6 +66,14 @@ class SidebarStore { get content() { return this.state.content } + + get component() { + return this.state.component + } + + get componentProps() { + return this.state.componentProps + } } export const sidebar = new SidebarStore() \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 458e9d08..50880f96 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -32,7 +32,9 @@ title={sidebar.title} onclose={() => sidebar.close()} > - {#if sidebar.content} + {#if sidebar.component} + + {:else if sidebar.content} {@render sidebar.content()} {/if} diff --git a/src/routes/test-sidebar/+page.svelte b/src/routes/test-sidebar/+page.svelte index d2a623e2..fb7494d2 100644 --- a/src/routes/test-sidebar/+page.svelte +++ b/src/routes/test-sidebar/+page.svelte @@ -3,9 +3,38 @@