diff --git a/frontend/src/lib/components/PersonTypeahead.svelte b/frontend/src/lib/components/PersonTypeahead.svelte index 91df7d02..5196108a 100644 --- a/frontend/src/lib/components/PersonTypeahead.svelte +++ b/frontend/src/lib/components/PersonTypeahead.svelte @@ -9,6 +9,7 @@ interface Props { label: string; value?: string; initialName?: string; + suggestedName?: string; restrictToCorrespondentsOf?: string; onchange?: (value: string) => void; } @@ -18,12 +19,20 @@ let { label, value = $bindable(''), initialName = '', + suggestedName = '', restrictToCorrespondentsOf, onchange }: Props = $props(); let searchTerm = $state(initialName); +$effect(() => { + const suggested = suggestedName; + if (suggested && !untrack(() => value)) { + searchTerm = suggested; + } +}); + let results: Person[] = $state([]); let showDropdown = $state(false); let loading = $state(false); diff --git a/frontend/src/lib/components/document/DescriptionSection.svelte b/frontend/src/lib/components/document/DescriptionSection.svelte index 10cda974..6d2c13c4 100644 --- a/frontend/src/lib/components/document/DescriptionSection.svelte +++ b/frontend/src/lib/components/document/DescriptionSection.svelte @@ -1,4 +1,5 @@
@@ -33,7 +46,11 @@ let { id="title" type="text" name="title" - value={initialTitle} + value={titleValue} + oninput={(e) => { + titleValue = (e.target as HTMLInputElement).value; + titleDirty = true; + }} required={titleRequired} class="block w-full rounded border border-line p-2 text-sm shadow-sm focus:border-ink focus:ring-ink" /> diff --git a/frontend/src/lib/components/document/WhoWhenSection.svelte b/frontend/src/lib/components/document/WhoWhenSection.svelte index 71b2feaf..ff90efdf 100644 --- a/frontend/src/lib/components/document/WhoWhenSection.svelte +++ b/frontend/src/lib/components/document/WhoWhenSection.svelte @@ -16,13 +16,17 @@ let { selectedReceivers = $bindable([]), initialDateIso = '', initialLocation = '', - initialSenderName = '' + initialSenderName = '', + suggestedDateIso = '', + suggestedSenderName = '' }: { senderId?: string; selectedReceivers?: Person[]; initialDateIso?: string; initialLocation?: string; initialSenderName?: string; + suggestedDateIso?: string; + suggestedSenderName?: string; } = $props(); let dateDisplay = $state(untrack(() => isoToGerman(initialDateIso))); @@ -37,6 +41,14 @@ function handleDateInput(e: Event) { dateIso = result.iso; dateDirty = true; } + +$effect(() => { + const suggested = suggestedDateIso; + if (suggested && !untrack(() => dateDirty)) { + dateDisplay = isoToGerman(suggested); + dateIso = suggested; + } +});
@@ -90,6 +102,7 @@ function handleDateInput(e: Event) { label={m.form_label_sender()} bind:value={senderId} initialName={initialSenderName} + suggestedName={suggestedSenderName} />
diff --git a/frontend/src/routes/documents/new/+page.svelte b/frontend/src/routes/documents/new/+page.svelte index 6eb3b0c8..ac2d8a6f 100644 --- a/frontend/src/routes/documents/new/+page.svelte +++ b/frontend/src/routes/documents/new/+page.svelte @@ -6,6 +6,7 @@ import WhoWhenSection from '$lib/components/document/WhoWhenSection.svelte'; import DescriptionSection from '$lib/components/document/DescriptionSection.svelte'; import TranscriptionSection from '$lib/components/document/TranscriptionSection.svelte'; import FileSectionNew from './FileSectionNew.svelte'; +import { type FilenameParseResult } from '$lib/utils/filename'; let { data, form } = $props(); @@ -14,6 +15,8 @@ let senderId = $state(untrack(() => data.initialSenderId)); let selectedReceivers: { id: string; firstName: string; lastName: string }[] = $state( untrack(() => data.initialReceivers) ); + +let parsedSuggestion = $state({});
@@ -50,10 +53,16 @@ let selectedReceivers: { id: string; firstName: string; lastName: string }[] = $ bind:senderId={senderId} bind:selectedReceivers={selectedReceivers} initialSenderName={data.initialSenderName} + suggestedDateIso={parsedSuggestion.dateIso ?? ''} + suggestedSenderName={parsedSuggestion.personName ?? ''} + /> + - - + (parsedSuggestion = r)} />
import { m } from '$lib/paraglide/messages.js'; +import { parseFilename, type FilenameParseResult } from '$lib/utils/filename'; + +let { + onfileParsed +}: { + onfileParsed?: (result: FilenameParseResult) => void; +} = $props(); + +function handleFileChange(e: Event) { + const file = (e.target as HTMLInputElement).files?.[0]; + if (file) onfileParsed?.(parseFilename(file.name)); +}
@@ -15,6 +27,7 @@ import { m } from '$lib/paraglide/messages.js'; id="file-upload" type="file" name="file" + onchange={handleFileChange} class="block w-full cursor-pointer text-sm text-ink-2 file:mr-4 file:rounded file:border-0 file:bg-muted