diff --git a/webui/src/lib/components/utils/NotesEditor.svelte b/webui/src/lib/components/utils/NotesEditor.svelte index 403d005..5e26626 100644 --- a/webui/src/lib/components/utils/NotesEditor.svelte +++ b/webui/src/lib/components/utils/NotesEditor.svelte @@ -5,16 +5,20 @@ import type { AttributeCreate, AttributeUpdate } from '$lib/types/base'; import type { UpEntry } from '@upnd/upend'; import LabelBorder from './LabelBorder.svelte'; + import { i18n } from '$lib/i18n'; + import { format } from 'date-fns'; const dispatch = createEventDispatcher(); export let address: string; + let lastSaved: Date | undefined; + $: ({ entity } = useEntity(address)); let noteEntry: UpEntry | undefined; let notes: string | undefined = undefined; $: { - if ($entity?.attr['NOTE']?.length && $entity?.attr['NOTE'][0]?.value?.c) { + if ($entity?.attr['NOTE']?.[0]?.value?.c) { noteEntry = $entity?.attr['NOTE'][0]; notes = String(noteEntry.value.c); } else { @@ -41,14 +45,27 @@ value: { t: 'String', c: contentEl.innerText } } as AttributeCreate); } + lastSaved = new Date(); }, 500); + + function onInput() { + lastSaved = undefined; + update(); + } Notes -
+
{notes ? notes : ''}
+
+ {#if lastSaved} + {$i18n.t('Last saved at {{time}}', { time: format(lastSaved, 'HH:mm') })} + {:else} + {$i18n.t('Waiting for changes...')} + {/if} +