feat(bulk-edit): add /documents/bulk-edit route
Server load redirects READ_ALL-only users (or unauthenticated) to /documents. Page load: onMount reads bulkSelectionStore — redirects to /documents when the store is empty, otherwise POSTs the IDs to /api/documents/batch-metadata and hands the resulting summaries to BulkDocumentEditLayout in mode="edit". Refs #225 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
53
frontend/src/routes/documents/bulk-edit/+page.svelte
Normal file
53
frontend/src/routes/documents/bulk-edit/+page.svelte
Normal file
@@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { bulkSelectionStore } from '$lib/stores/bulkSelection.svelte';
|
||||
import BulkDocumentEditLayout, {
|
||||
type BulkEditEntry
|
||||
} from '$lib/components/document/BulkDocumentEditLayout.svelte';
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
|
||||
let entries = $state<BulkEditEntry[]>([]);
|
||||
let loading = $state(true);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
onMount(async () => {
|
||||
const ids = Array.from(bulkSelectionStore.ids);
|
||||
if (ids.length === 0) {
|
||||
await goto('/documents');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await fetch('/api/documents/batch-metadata', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ids })
|
||||
});
|
||||
if (!res.ok) {
|
||||
error = m.error_internal_error();
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
const summaries = (await res.json()) as BulkEditEntry[];
|
||||
entries = summaries;
|
||||
} catch {
|
||||
error = m.error_internal_error();
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{m.bulk_edit_title()} – Familienarchiv</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if loading}
|
||||
<div class="flex h-full items-center justify-center p-12 text-sm text-ink-2">…</div>
|
||||
{:else if error}
|
||||
<div class="m-6 rounded-sm border border-red-300 bg-red-50 p-4 text-sm text-red-700">
|
||||
{error}
|
||||
</div>
|
||||
{:else if entries.length > 0}
|
||||
<BulkDocumentEditLayout mode="edit" initialEditEntries={entries} />
|
||||
{/if}
|
||||
Reference in New Issue
Block a user