From 91d53530e6e9dd3e5ed410cbd4839a38de04361d Mon Sep 17 00:00:00 2001 From: rdavis Date: Thu, 13 Jun 2024 23:24:52 +0000 Subject: [PATCH 1/3] 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'))} +
+
From 26575c508669489d1515a67e7370e4f22de10afb Mon Sep 17 00:00:00 2001 From: rdavis Date: Thu, 13 Jun 2024 23:59:15 +0000 Subject: [PATCH 2/3] Changed column header text to match property. Removed debugging code. --- src/lib/components/admin/UserChatsModal.svelte | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lib/components/admin/UserChatsModal.svelte b/src/lib/components/admin/UserChatsModal.svelte index a36b0af69..7a2dea048 100644 --- a/src/lib/components/admin/UserChatsModal.svelte +++ b/src/lib/components/admin/UserChatsModal.svelte @@ -42,9 +42,6 @@ sortOrder = 'asc'; } } - $: { - console.log(chats); - } @@ -84,7 +81,7 @@ > setSortKey('title')}> - {$i18n.t('Name')} + {$i18n.t('Title')} {#if sortKey === 'title'} {sortOrder === 'asc' ? '▲' : '▼'} {:else} From b0d9aa38d2fb0c76790bd72081e969357d29f49b Mon Sep 17 00:00:00 2001 From: rdavis Date: Fri, 14 Jun 2024 00:07:21 +0000 Subject: [PATCH 3/3] Swapped from inline style to using tailwind class. --- src/lib/components/admin/UserChatsModal.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/components/admin/UserChatsModal.svelte b/src/lib/components/admin/UserChatsModal.svelte index 7a2dea048..e1590f268 100644 --- a/src/lib/components/admin/UserChatsModal.svelte +++ b/src/lib/components/admin/UserChatsModal.svelte @@ -85,7 +85,7 @@ {#if sortKey === 'title'} {sortOrder === 'asc' ? '▲' : '▼'} {:else} - + {/if} setSortKey('created_at')}> @@ -93,7 +93,7 @@ {#if sortKey === 'created_at'} {sortOrder === 'asc' ? '▲' : '▼'} {:else} - + {/if} setSortKey('updated_at')}> @@ -101,7 +101,7 @@ {#if sortKey === 'updated_at'} {sortOrder === 'asc' ? '▲' : '▼'} {:else} - + {/if}