From beec78fb474121890c5148b77334819cf38b05ec Mon Sep 17 00:00:00 2001 From: Frederic Cabassut Date: Fri, 6 Mar 2026 21:23:27 +0100 Subject: [PATCH] feat: deep link to open notes via URL hash Opening a note sets the URL to /#note-id, closing clears it. On page load, the hash is read and the corresponding note is opened. Uses replaceState to avoid polluting browser history. Co-Authored-By: Claude Opus 4.6 --- src/routes/+page.svelte | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 28bf88a..b61a6bf 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,7 +2,9 @@ import NoteGrid from '$lib/components/NoteGrid.svelte'; import NoteEditor from '$lib/components/NoteEditor.svelte'; import TagFilter from '$lib/components/TagFilter.svelte'; - import { pinnedNotes, unpinnedNotes, selectedTag, currentFilter } from '$lib/stores/notes.js'; + import { pinnedNotes, unpinnedNotes, selectedTag, currentFilter, notes } from '$lib/stores/notes.js'; + import { onMount } from 'svelte'; + import { get } from 'svelte/store'; import type { Note } from '$lib/types/index.js'; let editingNote: Note | null = $state(null); @@ -10,12 +12,27 @@ function openEditor(note: Note) { editingNote = note; + history.replaceState(null, '', `#${note.id}`); } function closeEditor() { editingNote = null; showNewNote = false; + history.replaceState(null, '', location.pathname); } + + onMount(() => { + const hash = location.hash.slice(1); + if (!hash) return; + + // Notes may not be loaded yet — wait for them + const unsubscribe = notes.subscribe(($notes) => { + if ($notes.length === 0) return; + const note = $notes.find((n) => n.id === hash); + if (note) editingNote = note; + unsubscribe(); + }); + });