From 38d558182a9306502cd6fa61f7205693c7cf88a6 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 15 Apr 2026 09:41:40 +0200 Subject: [PATCH] refactor(conversations): migrate ConversationTimeline to groupDocuments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace hand-rolled enrichedDocuments year-divider logic with the shared groupDocuments utility. Also fixes a timezone bug in documentYears: adds 'T12:00:00' to date strings so getFullYear() doesn't drift on UTC boundaries. No behavior change — year dividers render the same way as before. Co-Authored-By: Claude Sonnet 4.6 --- .../conversations/ConversationTimeline.svelte | 124 +++++++++--------- 1 file changed, 60 insertions(+), 64 deletions(-) diff --git a/frontend/src/routes/conversations/ConversationTimeline.svelte b/frontend/src/routes/conversations/ConversationTimeline.svelte index feb6d9f7..ecc9d14a 100644 --- a/frontend/src/routes/conversations/ConversationTimeline.svelte +++ b/frontend/src/routes/conversations/ConversationTimeline.svelte @@ -2,6 +2,7 @@ import { m } from '$lib/paraglide/messages.js'; import { formatDate } from '$lib/utils/date'; import GroupDivider from '$lib/components/GroupDivider.svelte'; +import { groupDocuments } from '$lib/utils/groupDocuments'; let { documents, @@ -30,22 +31,15 @@ let { const documentYears = $derived( documents - .map((doc) => (doc.documentDate ? new Date(doc.documentDate).getFullYear() : null)) + .map((doc) => + doc.documentDate ? new Date(doc.documentDate + 'T12:00:00').getFullYear() : null + ) .filter((y): y is number => y !== null) ); const yearFrom = $derived(documentYears.length > 0 ? Math.min(...documentYears) : null); const yearTo = $derived(documentYears.length > 0 ? Math.max(...documentYears) : null); -const enrichedDocuments = $derived( - documents.map((doc, i) => { - const year = doc.documentDate ? new Date(doc.documentDate).getFullYear() : null; - const prevYear = - i > 0 && documents[i - 1].documentDate - ? new Date(documents[i - 1].documentDate!).getFullYear() - : null; - return { doc, year, showYearDivider: year !== null && year !== prevYear }; - }) -); +const documentGroups = $derived.by(() => groupDocuments(documents, 'DATE', '')); @@ -83,81 +77,83 @@ const enrichedDocuments = $derived(
- {#each enrichedDocuments as { doc, year, showYearDivider } (doc.id)} - {#if showYearDivider} - + {#each documentGroups as group (group.label)} + {#if group.label} + {/if} - {@const isRight = doc.sender?.id === senderId} + {#each group.documents as doc (doc.id)} + {@const isRight = doc.sender?.id === senderId} - -
- -
+ +
- - - - - -
-

+

- {doc.title || doc.originalFilename} -

+ > + {doc.title || doc.originalFilename} + - - - -
+ title={doc.status} + > + +
- - - + {#if doc.location} + + • {doc.location} + + {/if} +
+ +
-
+ {/each} {/each}