feat(new-doc): pre-fill date, sender and title from parsed filename

When a file is selected on the new document page, parseFilename runs
on the filename and suggests date, sender name and title via the new
suggestedDateIso / suggestedSenderName / suggestedTitle props. Each
suggestion is applied only while the respective field is still clean
(not dirty), so manual input is never overwritten.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-26 15:17:47 +01:00
parent 8555193a79
commit 078bc1c886
5 changed files with 66 additions and 5 deletions

View File

@@ -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<FilenameParseResult>({});
</script>
<div class="mx-auto max-w-4xl px-4 py-8">
@@ -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 ?? ''}
/>
<DescriptionSection
bind:tags={tags}
titleRequired={true}
suggestedTitle={parsedSuggestion.suggestedTitle ?? ''}
/>
<DescriptionSection bind:tags={tags} titleRequired={true} />
<TranscriptionSection />
<FileSectionNew />
<FileSectionNew onfileParsed={(r) => (parsedSuggestion = r)} />
<!-- Sticky Save Bar -->
<div

View File

@@ -1,5 +1,17 @@
<script lang="ts">
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));
}
</script>
<div class="rounded-sm border border-line bg-surface p-6 shadow-sm">
@@ -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