From 3f577c0c3fbfd9f09c02940e4ae474f987149277 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 5 Jan 2026 17:34:29 +0400 Subject: [PATCH] refac: notes organization issue --- src/lib/components/notes/Notes.svelte | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lib/components/notes/Notes.svelte b/src/lib/components/notes/Notes.svelte index 3d0ceb60b..61247b32f 100644 --- a/src/lib/components/notes/Notes.svelte +++ b/src/lib/components/notes/Notes.svelte @@ -215,22 +215,27 @@ const groupNotes = (res) => { if (!Array.isArray(res)) { - return {}; // or throw new Error("Notes response is not an array") + return []; // Return empty array for invalid input } - // Build the grouped object + // Build the grouped object while tracking order const grouped: Record = {}; + const orderedKeys: string[] = []; + for (const note of res) { const timeRange = getTimeRange(note.updated_at / 1000000000); if (!grouped[timeRange]) { grouped[timeRange] = []; + orderedKeys.push(timeRange); } grouped[timeRange].push({ ...note, timeRange }); } - return grouped; + + // Return as array of [timeRange, notes] to preserve insertion order + return orderedKeys.map(key => [key, grouped[key]] as [string, any[]]); }; let dragged = false; @@ -437,11 +442,11 @@ {#if items !== null && total !== null} {#if (items ?? []).length > 0} - {@const notes = groupNotes(items)} + {@const groupedNotes = groupNotes(items)}
- {#each Object.keys(notes) as timeRange, idx} + {#each groupedNotes as [timeRange, notesList], idx}
@@ -450,11 +455,11 @@ {#if displayOption === null}
- {#each notes[timeRange] as note, idx (note.id)} + {#each notesList as note, idx (note.id)}
@@ -536,11 +541,11 @@
{:else if displayOption === 'grid'}
- {#each notes[timeRange] as note, idx (note.id)} + {#each notesList as note, idx (note.id)}