From 91d53530e6e9dd3e5ed410cbd4839a38de04361d Mon Sep 17 00:00:00 2001 From: rdavis Date: Thu, 13 Jun 2024 23:24:52 +0000 Subject: [PATCH] Added the ability to sort chats in the admin panel chats modal Added "Updated at" column to the admin panel chats modal. --- .../components/admin/UserChatsModal.svelte | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/lib/components/admin/UserChatsModal.svelte b/src/lib/components/admin/UserChatsModal.svelte index 67fa367cd..a36b0af69 100644 --- a/src/lib/components/admin/UserChatsModal.svelte +++ b/src/lib/components/admin/UserChatsModal.svelte @@ -31,6 +31,20 @@ } })(); } + + let sortKey = 'updated_at'; // default sort key + let sortOrder = 'desc'; // default sort order + function setSortKey(key) { + if (sortKey === key) { + sortOrder = sortOrder === 'asc' ? 'desc' : 'asc'; + } else { + sortKey = key; + sortOrder = 'asc'; + } + } + $: { + console.log(chats); + } @@ -69,18 +83,45 @@ class="text-xs text-gray-700 uppercase bg-transparent dark:text-gray-200 border-b-2 dark:border-gray-800" > - {$i18n.t('Name')} - {$i18n.t('Created at')} + setSortKey('title')}> + {$i18n.t('Name')} + {#if sortKey === 'title'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} + + setSortKey('created_at')}> + {$i18n.t('Created at')} + {#if sortKey === 'created_at'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} + + setSortKey('updated_at')}> + {$i18n.t('Updated at')} + {#if sortKey === 'updated_at'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} + - {#each chats as chat, idx} + {#each chats + .sort((a, b) => { + if (a[sortKey] < b[sortKey]) return sortOrder === 'asc' ? -1 : 1; + if (a[sortKey] > b[sortKey]) return sortOrder === 'asc' ? 1 : -1; + return 0; + }) as chat, idx} - +
{chat.title} @@ -88,11 +129,16 @@ - +
{dayjs(chat.created_at * 1000).format($i18n.t('MMMM DD, YYYY HH:mm'))}
+ +
+ {dayjs(chat.updated_at * 1000).format($i18n.t('MMMM DD, YYYY HH:mm'))} +
+