feat(context): add inline document creation to workbench ListView

Adds a "Neues Dokument" button and an "Alle Dokumente" link in the
toolbar. Document rows are now clickable <a> tags linking to the
detail page instead of static divs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-10 17:36:31 +02:00
parent 26914b14c8
commit f1a7f35d66

View file

@ -3,12 +3,31 @@
Spaces and recent documents.
-->
<script lang="ts">
import { goto } from '$app/navigation';
import { useLiveQueryWithDefault } from '@mana/local-store/svelte';
import { db } from '$lib/data/database';
import { decryptRecords } from '$lib/data/crypto';
import { decryptRecords, encryptRecord } from '$lib/data/crypto';
import { BaseListView } from '@mana/shared-ui';
import { documentTable } from './collections';
import type { LocalContextSpace, LocalDocument } from './types';
async function handleCreateDocument() {
const id = crypto.randomUUID();
const row: LocalDocument = {
id,
spaceId: null,
title: 'Neues Dokument',
content: '# Neues Dokument\n\n',
type: 'text',
shortId: null,
pinned: false,
metadata: null,
};
await encryptRecord('documents', row);
await documentTable.add(row);
goto(`/context/documents/${id}`);
}
const spacesQuery = useLiveQueryWithDefault(async () => {
const all = await db.table<LocalContextSpace>('contextSpaces').toArray();
return all.filter((s) => !s.deletedAt);
@ -37,6 +56,25 @@
</script>
<BaseListView items={recentDocs} getKey={(d) => d.id} emptyTitle="Keine Dokumente">
{#snippet toolbar()}
<div class="flex items-center justify-between gap-2">
<a
href="/context/documents"
class="text-xs text-white/50 transition-colors hover:text-white/80"
>
Alle Dokumente &rarr;
</a>
<button
type="button"
onclick={handleCreateDocument}
class="flex items-center gap-1.5 rounded-md bg-indigo-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-indigo-700"
>
<span aria-hidden="true">+</span>
Neues Dokument
</button>
</div>
{/snippet}
{#snippet header()}
<span>{spaces.length} Spaces</span>
<span>{documents.length} Dokumente</span>
@ -58,7 +96,8 @@
{/snippet}
{#snippet item(doc)}
<div
<a
href="/context/documents/{doc.id}"
class="flex min-h-[44px] items-center gap-2 rounded-md px-2 py-1.5 transition-colors hover:bg-white/5"
>
<span class="text-sm">{@html typeIcons[doc.type] ?? '&#128196;'}</span>
@ -68,6 +107,6 @@
{#if doc.pinned}
<span class="text-xs text-white/30">&#128204;</span>
{/if}
</div>
</a>
{/snippet}
</BaseListView>