From 461cd3b5e7866600f4ac560c2bcb3e98d94e510c Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 15 Sep 2025 16:44:44 +0100 Subject: [PATCH] Bookmarking functionality and UI --- .../components/global/BookmarksGrid.svelte | 205 ++++++++++++++++++ src/lib/components/global/GlobalSearch.svelte | 129 ++++++++++- src/lib/components/global/Icon.svelte | 5 + src/lib/components/global/ToolCard.svelte | 180 +++++++++++++-- src/lib/stores/bookmarks.ts | 69 ++++++ src/routes/+page.svelte | 5 + src/routes/bookmarks/+page.svelte | 67 ++++++ 7 files changed, 640 insertions(+), 20 deletions(-) create mode 100644 src/lib/components/global/BookmarksGrid.svelte create mode 100644 src/lib/stores/bookmarks.ts create mode 100644 src/routes/bookmarks/+page.svelte diff --git a/src/lib/components/global/BookmarksGrid.svelte b/src/lib/components/global/BookmarksGrid.svelte new file mode 100644 index 0000000..8219403 --- /dev/null +++ b/src/lib/components/global/BookmarksGrid.svelte @@ -0,0 +1,205 @@ + + +{#if $bookmarks.length > 0} +
+ + {#if !hideOther} +
+
+ +

Bookmarked Tools

+ {$bookmarks.length} +
+
+ {/if} + +
+ +
+
+{:else if !hideOther} +
+
+ +
+

No bookmarks yet

+

Hover over any tool card and click the bookmark icon to save your favorites

+
+{/if} + + diff --git a/src/lib/components/global/GlobalSearch.svelte b/src/lib/components/global/GlobalSearch.svelte index f469ba7..c49e8ef 100644 --- a/src/lib/components/global/GlobalSearch.svelte +++ b/src/lib/components/global/GlobalSearch.svelte @@ -5,6 +5,7 @@ import Icon from './Icon.svelte'; import { ALL_PAGES } from '$lib/constants/nav'; import type { NavItem } from '$lib/constants/nav'; + import { bookmarks } from '$lib/stores/bookmarks'; let isOpen = $state(false); let query = $state(''); @@ -116,6 +117,7 @@ }); onMount(() => { + bookmarks.init(); document.addEventListener('keydown', handleGlobalKeydown); return () => document.removeEventListener('keydown', handleGlobalKeydown); }); @@ -159,16 +161,19 @@ onmouseenter={() => selectedIndex = index} >
-
{result.label}
+
+ + {result.label} +
{#if result.description}
{result.description}
{/if}
- {result.href} {#if index === selectedIndex} - + {/if} + {result.href}
{/each} @@ -189,12 +194,40 @@ Use ↑↓ to navigate, Enter to select + + {#if $bookmarks.length > 0} +
+
+ + Bookmarked Tools +
+
+ {#each $bookmarks.slice(0, 6) as bookmark, index} + + {/each} +
+
+ {/if} {/if} {/if} diff --git a/src/lib/stores/bookmarks.ts b/src/lib/stores/bookmarks.ts new file mode 100644 index 0000000..7ce432d --- /dev/null +++ b/src/lib/stores/bookmarks.ts @@ -0,0 +1,69 @@ +import { writable } from 'svelte/store'; +import { browser } from '$app/environment'; + +export interface BookmarkedTool { + href: string; + label: string; + description: string; + icon: string; +} + +const STORAGE_KEY = 'bookmarked-tools'; + +function createBookmarksStore() { + const { subscribe, set, update } = writable([]); + + return { + subscribe, + init: () => { + if (browser) { + const stored = localStorage.getItem(STORAGE_KEY); + if (stored) { + try { + set(JSON.parse(stored)); + } catch { + set([]); + } + } + } + }, + add: (tool: BookmarkedTool) => { + update(bookmarks => { + if (!bookmarks.find(b => b.href === tool.href)) { + const newBookmarks = [...bookmarks, tool]; + if (browser) { + localStorage.setItem(STORAGE_KEY, JSON.stringify(newBookmarks)); + } + return newBookmarks; + } + return bookmarks; + }); + }, + remove: (href: string) => { + update(bookmarks => { + const newBookmarks = bookmarks.filter(b => b.href !== href); + if (browser) { + localStorage.setItem(STORAGE_KEY, JSON.stringify(newBookmarks)); + } + return newBookmarks; + }); + }, + toggle: (tool: BookmarkedTool) => { + update(bookmarks => { + const existing = bookmarks.find(b => b.href === tool.href); + const newBookmarks = existing + ? bookmarks.filter(b => b.href !== tool.href) + : [...bookmarks, tool]; + if (browser) { + localStorage.setItem(STORAGE_KEY, JSON.stringify(newBookmarks)); + } + return newBookmarks; + }); + }, + isBookmarked: (href: string, bookmarks: BookmarkedTool[]) => { + return bookmarks.some(b => b.href === href); + } + }; +} + +export const bookmarks = createBookmarksStore(); \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index d66a566..1b90218 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -4,6 +4,7 @@ import { ALL_PAGES, SUB_NAV, type NavItem, type NavGroup } from '$lib/constants/nav'; import ToolsGrid from '$lib/components/global/ToolsGrid.svelte'; import SearchFilter from '$lib/components/furniture/SearchFilter.svelte'; + import BookmarksGrid from '$lib/components/global/BookmarksGrid.svelte'; // Helper function to extract nav items from mixed structure function extractNavItems(items: (NavItem | NavGroup)[]): NavItem[] { @@ -70,6 +71,10 @@ {#if searchQuery.trim() === ''} + + + + diff --git a/src/routes/bookmarks/+page.svelte b/src/routes/bookmarks/+page.svelte new file mode 100644 index 0000000..eca54b6 --- /dev/null +++ b/src/routes/bookmarks/+page.svelte @@ -0,0 +1,67 @@ + + + + {pages.home.title} + + + + + + + + + + + +{#if bookmarkCount > 0} +
+ +
+{/if} + + +{#if bookmarkCount === 0 || showAll} + +{/if} + + +