diff --git a/src/lib/components/chat/Settings/Personalization/ManageModal.svelte b/src/lib/components/chat/Settings/Personalization/ManageModal.svelte index 2fe039581..a4c08c2d8 100644 --- a/src/lib/components/chat/Settings/Personalization/ManageModal.svelte +++ b/src/lib/components/chat/Settings/Personalization/ManageModal.svelte @@ -9,10 +9,18 @@ import AddMemoryModal from './AddMemoryModal.svelte'; import { deleteMemoriesByUserId, deleteMemoryById, getMemories } from '$lib/apis/memories'; import Tooltip from '$lib/components/common/Tooltip.svelte'; - import { error } from '@sveltejs/kit'; import EditMemoryModal from './EditMemoryModal.svelte'; import localizedFormat from 'dayjs/plugin/localizedFormat'; import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte'; + import Spinner from '$lib/components/common/Spinner.svelte'; + + import XMark from '$lib/components/icons/XMark.svelte'; + import Pencil from '$lib/components/icons/Pencil.svelte'; + import GarbageBin from '$lib/components/icons/GarbageBin.svelte'; + import Plus from '$lib/components/icons/Plus.svelte'; + import Search from '$lib/components/icons/Search.svelte'; + import ChevronUp from '$lib/components/icons/ChevronUp.svelte'; + import ChevronDown from '$lib/components/icons/ChevronDown.svelte'; const i18n = getContext('i18n'); dayjs.extend(localizedFormat); @@ -22,6 +30,19 @@ let memories = []; let loading = true; + let query = ''; + let orderBy = 'updated_at'; + let direction = 'desc'; + + const setSortKey = (key: string) => { + if (orderBy === key) { + direction = direction === 'asc' ? 'desc' : 'asc'; + } else { + orderBy = key; + direction = 'asc'; + } + }; + let showAddMemoryModal = false; let showEditMemoryModal = false; @@ -29,6 +50,26 @@ let showClearConfirmDialog = false; + $: filteredMemories = query + ? memories.filter((m) => m.content?.toLowerCase().includes(query.toLowerCase())) + : memories; + + $: sortedMemories = [...filteredMemories].sort((a, b) => { + let aVal, bVal; + if (orderBy === 'content') { + aVal = (a.content ?? '').toLowerCase(); + bVal = (b.content ?? '').toLowerCase(); + } else { + aVal = a.updated_at ?? 0; + bVal = b.updated_at ?? 0; + } + if (direction === 'asc') { + return aVal > bVal ? 1 : -1; + } else { + return aVal < bVal ? 1 : -1; + } + }); + let onClearConfirmed = async () => { const res = await deleteMemoriesByUserId(localStorage.token).catch((error) => { toast.error(`${error}`); @@ -52,145 +93,185 @@
-
-
{$i18n.t('Memory')}
- -
+ +
+
+
{$i18n.t('Memory')}
-
-
- {#if memories.length > 0} -
-
- - - - - - - - - {#each memories as memory} - - - - - - {/each} - -
{$i18n.t('Name')} -
-
- {memory.content} -
-
-
- - - - - - - -
-
-
-
- {:else} -
-
- {$i18n.t('Memories accessible by LLMs will be shown here.')} -
+ {#if !loading} +
+ {memories.length}
{/if}
-
+ + +
+ +
+ +
+
+ +
+ + + {#if query} +
+ +
+ {/if} +
+ + +
+ {#if !loading} + {#if sortedMemories.length === 0} +
+ {#if memories.length === 0} + {$i18n.t('Memories accessible by LLMs will be shown here.')} + {:else} + {$i18n.t('No results found')} + {/if} +
+ {:else} + {#if sortedMemories.length > 0} +
+ + +
+ {/if} + +
+ {#each sortedMemories as memory (memory.id)} +
{ + selectedMemory = memory; + showEditMemoryModal = true; + }} + > +
+
{memory.content}
+
+ {dayjs(memory.updated_at * 1000).format('MMM D, YYYY')} +
+
+ +
+ + +
+ + + + + + + +
+
+
+ {/each} +
+ {/if} + {:else} +
+ +
+ {/if} +
+ + +
- + +