From 3f3a69568f6588939160fbf5ab1b8cf03d4509a7 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 4 Aug 2025 17:37:33 +0400 Subject: [PATCH] enh: ability to sort folder chats --- .../chat/Placeholder/ChatList.svelte | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/lib/components/chat/Placeholder/ChatList.svelte b/src/lib/components/chat/Placeholder/ChatList.svelte index 1e48298ec5..62869f7fc2 100644 --- a/src/lib/components/chat/Placeholder/ChatList.svelte +++ b/src/lib/components/chat/Placeholder/ChatList.svelte @@ -5,6 +5,8 @@ import dayjs from 'dayjs'; import localizedFormat from 'dayjs/plugin/localizedFormat'; import { getTimeRange } from '$lib/utils'; + import ChevronUp from '$lib/components/icons/ChevronUp.svelte'; + import ChevronDown from '$lib/components/icons/ChevronDown.svelte'; dayjs.extend(localizedFormat); @@ -20,15 +22,86 @@ ...chat, time_range: getTimeRange(chat.updated_at) })); + + chatList.sort((a, b) => { + if (direction === 'asc') { + return a[orderBy] > b[orderBy] ? 1 : -1; + } else { + return a[orderBy] < b[orderBy] ? 1 : -1; + } + }); } }; + const setSortKey = (key) => { + if (orderBy === key) { + direction = direction === 'asc' ? 'desc' : 'asc'; + } else { + orderBy = key; + direction = 'asc'; + } + + init(); + }; + + let orderBy = 'updated_at'; + let direction = 'desc'; // 'asc' or 'desc' + $: if (chats) { init(); } {#if chatList} + {#if chatList.length > 0} +
+ + +
+ {/if} +
{#if chatList.length === 0}