From 7b70afe648a8d953ebc979dad4bccf19b94ae9c5 Mon Sep 17 00:00:00 2001 From: Giuseppe Scuglia Date: Tue, 17 Dec 2024 19:30:24 +0100 Subject: [PATCH] fix: prompts sort (#9) --- src/lib/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b38b672..06e9773 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -47,7 +47,13 @@ function getGroup(differenceInMs: number, promptDate: Date): string { } export function groupPromptsByRelativeDate(prompts: Prompt[]) { - const grouped = prompts.reduce((groups, prompt) => { + const promptsSorted = prompts.sort( + (a, b) => + new Date(b.conversation_timestamp).getTime() - + new Date(a.conversation_timestamp).getTime() + ); + + const grouped = promptsSorted.reduce((groups, prompt) => { const promptDate = new Date(prompt.conversation_timestamp); const now = new Date(); const differenceInMs = now.getTime() - promptDate.getTime();