From 56b8e9956a56f4ffd18b2512c16e72ae065b5857 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 5 Mar 2026 13:54:51 -0500 Subject: [PATCH] refactor: simplify notes components to use service directly - Remove prop drilling, components get notes from NoteService context - NoteCard gets note by ID from service, uses {#key} for Markdown reactivity - NotesGrid handles filtering internally via service methods - NoteEditor gets service from context instead of prop - Add PageState type for shallow routing selectedNoteId - Add +layout.server.ts to pass user data to client Co-Authored-By: Claude Opus 4.5 --- src/app.d.ts | 4 +- src/routes/(app)/+layout.server.ts | 8 ++ src/routes/(app)/notes/+page.svelte | 49 ++------ src/routes/(app)/notes/NoteCard.svelte | 146 +++++++++++------------ src/routes/(app)/notes/NoteEditor.svelte | 45 ++++--- src/routes/(app)/notes/NotesGrid.svelte | 81 +++++-------- src/routes/(app)/notes/[id]/+page.svelte | 2 +- 7 files changed, 142 insertions(+), 193 deletions(-) create mode 100644 src/routes/(app)/+layout.server.ts diff --git a/src/app.d.ts b/src/app.d.ts index 2ae6f13..93f21d0 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -11,7 +11,9 @@ declare global { // interface Error {} // interface PageData {} - // interface PageState {} + interface PageState { + selectedNoteId?: string; + } // interface Platform {} } } diff --git a/src/routes/(app)/+layout.server.ts b/src/routes/(app)/+layout.server.ts new file mode 100644 index 0000000..90543e1 --- /dev/null +++ b/src/routes/(app)/+layout.server.ts @@ -0,0 +1,8 @@ +import type { LayoutServerLoad } from './$types'; + +export const load: LayoutServerLoad = async ({ locals }) => { + return { + user: locals.user, + session: locals.session + }; +}; diff --git a/src/routes/(app)/notes/+page.svelte b/src/routes/(app)/notes/+page.svelte index e630c02..7e7761e 100644 --- a/src/routes/(app)/notes/+page.svelte +++ b/src/routes/(app)/notes/+page.svelte @@ -1,4 +1,5 @@ - { - if (e.key === 'Enter' || e.key === ' ') { - e.preventDefault(); - onclick?.(); - } - }} -> -
-
- {#if note.pinned} - - {/if} -

{displayTitle}

-
-
e.stopPropagation()}> - -
-
- - - - {#if note.content} -
- -
- {/if} - - - {#if tags.length > 0} -
- {#each tags.slice(0, 3) as tag (tag)} - - {tag} - - {/each} - {#if tags.length > 3} - - +{tags.length - 3} - +{#if note} + (e.key === 'Enter' || e.key === ' ') && (e.preventDefault(), onclick?.())} + > +
+

+ {note.title || note.content.split('\n')[0] || 'Untitled'} +

+
+ {#if note.pinned} + {/if} +
- {/if} - +
- - - {formatRelativeTime(note.updatedAt)} - - -
+ + {#if note.content} +
+ {#key note.content} + + {/key} +
+ {/if} + + {#if note.tags.size > 0} + {@const tags = Array.from(note.tags)} +
+ {#each tags.slice(0, 3) as tag (tag)} + {tag} + {/each} + {#if tags.length > 3} + +{tags.length - 3} + {/if} +
+ {/if} +
+ + + {getRelativeTime(note.updatedAt)} + + +{/if} + diff --git a/src/routes/(app)/notes/NotesGrid.svelte b/src/routes/(app)/notes/NotesGrid.svelte index 877fdc8..63a0475 100644 --- a/src/routes/(app)/notes/NotesGrid.svelte +++ b/src/routes/(app)/notes/NotesGrid.svelte @@ -1,68 +1,49 @@ -{#if loading} - +{#if noteService.loading}
{#each Array(6) as _} -
- -
+ {/each}
-{:else if notes.length === 0} - -
-
- - - -
-

{emptyMessage}

-

- {#if emptyMessage === 'No notes found'} - Create your first note to get started. - {:else} - {emptyMessage} - {/if} -

-
{:else} - -
- {#each notes as note (note.id)} - onNoteClick?.(note)} /> - {/each} -
+ {@const baseNotes = filter === 'pinned' ? noteService.pinnedNotes : filter === 'archived' ? noteService.archivedNotes : filter === 'trash' ? noteService.trashedNotes : noteService.activeNotes} + {@const notes = search.trim() ? noteService.searchNotes(search, baseNotes) : baseNotes} + + {#if notes.length === 0} +
+
+ + + +
+

+ {search ? 'No notes match your search' : filter === 'pinned' ? 'No pinned notes' : filter === 'archived' ? 'No archived notes' : filter === 'trash' ? 'Trash is empty' : 'No notes yet'} +

+
+ {:else} +
+ {#each notes as note (note.id)} + onNoteClick?.(note.id)} /> + {/each} +
+ {/if} {/if} diff --git a/src/routes/(app)/notes/[id]/+page.svelte b/src/routes/(app)/notes/[id]/+page.svelte index 161f1a1..1ee8558 100644 --- a/src/routes/(app)/notes/[id]/+page.svelte +++ b/src/routes/(app)/notes/[id]/+page.svelte @@ -87,7 +87,7 @@
- +