feat(transcription): add block-level comment threads with quote support
Some checks failed
CI / Unit & Component Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Unit & Component Tests (pull_request) Failing after 1m33s
CI / Backend Unit Tests (pull_request) Failing after 2m47s
CI / E2E Tests (pull_request) Failing after 19m44s
Some checks failed
CI / Unit & Component Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Unit & Component Tests (pull_request) Failing after 1m33s
CI / Backend Unit Tests (pull_request) Failing after 2m47s
CI / E2E Tests (pull_request) Failing after 19m44s
TranscriptionBlock.svelte: - "Kommentieren" button opens expandable comment thread per block - Text selection in textarea captured as quoted text (> "...") prefix - Quote hint "Text markieren für Zitat" shown when block is active/focused - Comment thread uses existing CommentThread with blockId prop CommentThread.svelte: - Add blockId prop for block-level comments URL routing - Add quotedText prop — pre-fills comment input with markdown blockquote - commentsBase now supports 3 URL patterns: document, annotation, block TranscriptionEditView.svelte: - Pass canComment + currentUserId through to block components 3 new frontend tests: - Kommentieren button present - Quote hint shown when active - Quote hint hidden when inactive Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,24 +9,28 @@ import type { MentionDTO } from '$lib/types';
|
|||||||
type Props = {
|
type Props = {
|
||||||
documentId: string;
|
documentId: string;
|
||||||
annotationId?: string | null;
|
annotationId?: string | null;
|
||||||
|
blockId?: string | null;
|
||||||
initialComments?: Comment[];
|
initialComments?: Comment[];
|
||||||
loadOnMount?: boolean;
|
loadOnMount?: boolean;
|
||||||
canComment: boolean;
|
canComment: boolean;
|
||||||
currentUserId: string | null;
|
currentUserId: string | null;
|
||||||
canAdmin: boolean;
|
canAdmin: boolean;
|
||||||
targetCommentId?: string | null;
|
targetCommentId?: string | null;
|
||||||
|
quotedText?: string | null;
|
||||||
onCountChange?: (count: number) => void;
|
onCountChange?: (count: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
let {
|
let {
|
||||||
documentId,
|
documentId,
|
||||||
annotationId = null,
|
annotationId = null,
|
||||||
|
blockId = null,
|
||||||
initialComments = [],
|
initialComments = [],
|
||||||
loadOnMount = false,
|
loadOnMount = false,
|
||||||
canComment,
|
canComment,
|
||||||
currentUserId,
|
currentUserId,
|
||||||
canAdmin,
|
canAdmin,
|
||||||
targetCommentId = null,
|
targetCommentId = null,
|
||||||
|
quotedText = null,
|
||||||
onCountChange
|
onCountChange
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
@@ -43,11 +47,20 @@ let replyMentionCandidates: MentionDTO[] = $state([]);
|
|||||||
let editMentionCandidates: MentionDTO[] = $state([]);
|
let editMentionCandidates: MentionDTO[] = $state([]);
|
||||||
|
|
||||||
const commentsBase = $derived(
|
const commentsBase = $derived(
|
||||||
annotationId
|
blockId
|
||||||
? `/api/documents/${documentId}/annotations/${annotationId}/comments`
|
? `/api/documents/${documentId}/transcription-blocks/${blockId}/comments`
|
||||||
: `/api/documents/${documentId}/comments`
|
: annotationId
|
||||||
|
? `/api/documents/${documentId}/annotations/${annotationId}/comments`
|
||||||
|
: `/api/documents/${documentId}/comments`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Pre-fill comment box with quoted text when selection changes
|
||||||
|
$effect(() => {
|
||||||
|
if (quotedText && quotedText.trim()) {
|
||||||
|
newText = `> "${quotedText}"\n\n`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function timeAgo(iso: string): string {
|
function timeAgo(iso: string): string {
|
||||||
const diff = Date.now() - new Date(iso).getTime();
|
const diff = Date.now() - new Date(iso).getTime();
|
||||||
const minutes = Math.floor(diff / 60000);
|
const minutes = Math.floor(diff / 60000);
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
|
import CommentThread from './CommentThread.svelte';
|
||||||
|
|
||||||
type SaveState = 'idle' | 'saving' | 'saved' | 'fading' | 'error';
|
type SaveState = 'idle' | 'saving' | 'saved' | 'fading' | 'error';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
blockId: string;
|
blockId: string;
|
||||||
|
documentId: string;
|
||||||
blockNumber: number;
|
blockNumber: number;
|
||||||
text: string;
|
text: string;
|
||||||
label: string | null;
|
label: string | null;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
saveState: SaveState;
|
saveState: SaveState;
|
||||||
|
canComment: boolean;
|
||||||
|
currentUserId: string | null;
|
||||||
onTextChange: (text: string) => void;
|
onTextChange: (text: string) => void;
|
||||||
onFocus: () => void;
|
onFocus: () => void;
|
||||||
onDeleteClick: () => void;
|
onDeleteClick: () => void;
|
||||||
@@ -18,22 +22,30 @@ type Props = {
|
|||||||
|
|
||||||
let {
|
let {
|
||||||
blockId,
|
blockId,
|
||||||
|
documentId,
|
||||||
blockNumber,
|
blockNumber,
|
||||||
text,
|
text,
|
||||||
label = null,
|
label = null,
|
||||||
active,
|
active,
|
||||||
saveState,
|
saveState,
|
||||||
|
canComment,
|
||||||
|
currentUserId,
|
||||||
onTextChange,
|
onTextChange,
|
||||||
onFocus,
|
onFocus,
|
||||||
onDeleteClick,
|
onDeleteClick,
|
||||||
onRetry
|
onRetry
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
|
let commentOpen = $state(false);
|
||||||
|
let selectedQuote = $state<string | null>(null);
|
||||||
|
let textareaEl = $state<HTMLTextAreaElement | null>(null);
|
||||||
|
|
||||||
let leftBorderClass = $derived(
|
let leftBorderClass = $derived(
|
||||||
saveState === 'error' ? 'border-l-2 border-error' : active ? 'border-l-2 border-turquoise' : ''
|
saveState === 'error' ? 'border-l-2 border-error' : active ? 'border-l-2 border-turquoise' : ''
|
||||||
);
|
);
|
||||||
|
|
||||||
function autoresize(node: HTMLTextAreaElement) {
|
function autoresize(node: HTMLTextAreaElement) {
|
||||||
|
textareaEl = node;
|
||||||
function resize() {
|
function resize() {
|
||||||
node.style.height = 'auto';
|
node.style.height = 'auto';
|
||||||
node.style.height = `${node.scrollHeight}px`;
|
node.style.height = `${node.scrollHeight}px`;
|
||||||
@@ -45,7 +57,9 @@ function autoresize(node: HTMLTextAreaElement) {
|
|||||||
update() {
|
update() {
|
||||||
resize();
|
resize();
|
||||||
},
|
},
|
||||||
destroy() {}
|
destroy() {
|
||||||
|
textareaEl = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +73,19 @@ function handleDelete() {
|
|||||||
onDeleteClick();
|
onDeleteClick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function captureSelectionAndOpenComments() {
|
||||||
|
if (textareaEl) {
|
||||||
|
const start = textareaEl.selectionStart;
|
||||||
|
const end = textareaEl.selectionEnd;
|
||||||
|
if (start !== end) {
|
||||||
|
selectedQuote = textareaEl.value.substring(start, end);
|
||||||
|
} else {
|
||||||
|
selectedQuote = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commentOpen = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -93,7 +120,22 @@ function handleDelete() {
|
|||||||
></textarea>
|
></textarea>
|
||||||
|
|
||||||
<!-- Footer -->
|
<!-- Footer -->
|
||||||
<div class="flex items-center justify-end border-t border-line pt-2">
|
<div class="flex items-center justify-between border-t border-line pt-2">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="text-xs font-medium text-ink-2 transition-colors hover:text-ink"
|
||||||
|
onclick={captureSelectionAndOpenComments}
|
||||||
|
>
|
||||||
|
{m.transcription_block_comment_btn()}
|
||||||
|
</button>
|
||||||
|
{#if active}
|
||||||
|
<span class="text-xs text-ink-3">
|
||||||
|
{m.transcription_block_quote_hint()}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<!-- Save state indicator -->
|
<!-- Save state indicator -->
|
||||||
{#if saveState === 'saving'}
|
{#if saveState === 'saving'}
|
||||||
@@ -143,5 +185,35 @@ function handleDelete() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Comment thread (expandable) -->
|
||||||
|
{#if commentOpen}
|
||||||
|
<div class="mt-3 border-t border-line pt-3">
|
||||||
|
<div class="mb-2 flex items-center justify-between">
|
||||||
|
<span class="font-sans text-xs font-semibold text-ink-2">
|
||||||
|
{m.comment_section_title()}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="font-sans text-xs text-ink-3 transition-colors hover:text-ink"
|
||||||
|
onclick={() => {
|
||||||
|
commentOpen = false;
|
||||||
|
selectedQuote = null;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{m.comment_panel_close()}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<CommentThread
|
||||||
|
documentId={documentId}
|
||||||
|
blockId={blockId}
|
||||||
|
loadOnMount={true}
|
||||||
|
canComment={canComment}
|
||||||
|
currentUserId={currentUserId}
|
||||||
|
canAdmin={false}
|
||||||
|
quotedText={selectedQuote}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ afterEach(cleanup);
|
|||||||
function renderBlock(overrides: Record<string, unknown> = {}) {
|
function renderBlock(overrides: Record<string, unknown> = {}) {
|
||||||
return render(TranscriptionBlock, {
|
return render(TranscriptionBlock, {
|
||||||
blockId: 'block-1',
|
blockId: 'block-1',
|
||||||
|
documentId: 'doc-1',
|
||||||
blockNumber: 3,
|
blockNumber: 3,
|
||||||
text: 'Liebe Mutter,',
|
text: 'Liebe Mutter,',
|
||||||
label: null,
|
label: null,
|
||||||
active: false,
|
active: false,
|
||||||
saveState: 'idle' as const,
|
saveState: 'idle' as const,
|
||||||
|
canComment: true,
|
||||||
|
currentUserId: 'user-1',
|
||||||
onTextChange: vi.fn(),
|
onTextChange: vi.fn(),
|
||||||
onFocus: vi.fn(),
|
onFocus: vi.fn(),
|
||||||
onDeleteClick: vi.fn(),
|
onDeleteClick: vi.fn(),
|
||||||
@@ -111,4 +114,21 @@ describe('TranscriptionBlock — interactions', () => {
|
|||||||
await textarea.click();
|
await textarea.click();
|
||||||
expect(onFocus).toHaveBeenCalled();
|
expect(onFocus).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows Kommentieren button that opens comment thread', async () => {
|
||||||
|
renderBlock();
|
||||||
|
const btn = page.getByText('Kommentieren');
|
||||||
|
await expect.element(btn).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows quote hint when block is active', async () => {
|
||||||
|
renderBlock({ active: true });
|
||||||
|
await expect.element(page.getByText('Text markieren für Zitat')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hides quote hint when block is not active', async () => {
|
||||||
|
renderBlock({ active: false });
|
||||||
|
const hint = page.getByText('Text markieren für Zitat');
|
||||||
|
await expect.element(hint).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,12 +9,22 @@ type SaveState = 'idle' | 'saving' | 'saved' | 'fading' | 'error';
|
|||||||
type Props = {
|
type Props = {
|
||||||
documentId: string;
|
documentId: string;
|
||||||
blocks: TranscriptionBlockData[];
|
blocks: TranscriptionBlockData[];
|
||||||
|
canComment: boolean;
|
||||||
|
currentUserId: string | null;
|
||||||
onBlockFocus: (blockId: string) => void;
|
onBlockFocus: (blockId: string) => void;
|
||||||
onSaveBlock: (blockId: string, text: string) => Promise<void>;
|
onSaveBlock: (blockId: string, text: string) => Promise<void>;
|
||||||
onDeleteBlock: (blockId: string) => Promise<void>;
|
onDeleteBlock: (blockId: string) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
let { documentId, blocks, onBlockFocus, onSaveBlock, onDeleteBlock }: Props = $props();
|
let {
|
||||||
|
documentId,
|
||||||
|
blocks,
|
||||||
|
canComment,
|
||||||
|
currentUserId,
|
||||||
|
onBlockFocus,
|
||||||
|
onSaveBlock,
|
||||||
|
onDeleteBlock
|
||||||
|
}: Props = $props();
|
||||||
|
|
||||||
let activeBlockId: string | null = $state(null);
|
let activeBlockId: string | null = $state(null);
|
||||||
let saveStates = new SvelteMap<string, SaveState>();
|
let saveStates = new SvelteMap<string, SaveState>();
|
||||||
@@ -149,11 +159,14 @@ $effect(() => {
|
|||||||
<div onblur={handleBlur}>
|
<div onblur={handleBlur}>
|
||||||
<TranscriptionBlock
|
<TranscriptionBlock
|
||||||
blockId={block.id}
|
blockId={block.id}
|
||||||
|
documentId={documentId}
|
||||||
blockNumber={i + 1}
|
blockNumber={i + 1}
|
||||||
text={block.text}
|
text={block.text}
|
||||||
label={block.label}
|
label={block.label}
|
||||||
active={activeBlockId === block.id}
|
active={activeBlockId === block.id}
|
||||||
saveState={getSaveState(block.id)}
|
saveState={getSaveState(block.id)}
|
||||||
|
canComment={canComment}
|
||||||
|
currentUserId={currentUserId}
|
||||||
onTextChange={(text) => handleTextChange(block.id, text)}
|
onTextChange={(text) => handleTextChange(block.id, text)}
|
||||||
onFocus={() => handleFocus(block.id)}
|
onFocus={() => handleFocus(block.id)}
|
||||||
onDeleteClick={() => handleDelete(block.id)}
|
onDeleteClick={() => handleDelete(block.id)}
|
||||||
|
|||||||
@@ -234,6 +234,8 @@ onMount(() => {
|
|||||||
<TranscriptionEditView
|
<TranscriptionEditView
|
||||||
documentId={doc.id}
|
documentId={doc.id}
|
||||||
blocks={transcriptionBlocks}
|
blocks={transcriptionBlocks}
|
||||||
|
canComment={canComment}
|
||||||
|
currentUserId={currentUserId}
|
||||||
onBlockFocus={handleBlockFocus}
|
onBlockFocus={handleBlockFocus}
|
||||||
onSaveBlock={saveBlock}
|
onSaveBlock={saveBlock}
|
||||||
onDeleteBlock={deleteBlock}
|
onDeleteBlock={deleteBlock}
|
||||||
|
|||||||
Reference in New Issue
Block a user