diff --git a/frontend/src/lib/components/CommentThread.svelte b/frontend/src/lib/components/CommentThread.svelte index 5fa6bbbf..f908d7a3 100644 --- a/frontend/src/lib/components/CommentThread.svelte +++ b/frontend/src/lib/components/CommentThread.svelte @@ -2,6 +2,9 @@ import { onMount, untrack } from 'svelte'; import { m } from '$lib/paraglide/messages.js'; import type { Comment, CommentReply } from '$lib/types'; +import MentionEditor from '$lib/components/MentionEditor.svelte'; +import { renderBody, extractContent } from '$lib/utils/mention'; +import type { MentionDTO } from '$lib/types'; type Props = { documentId: string; @@ -32,6 +35,9 @@ let replyText: string = $state(''); let editingId: string | null = $state(null); let editText: string = $state(''); let posting: boolean = $state(false); +let newMentionCandidates: MentionDTO[] = $state([]); +let replyMentionCandidates: MentionDTO[] = $state([]); +let editMentionCandidates: MentionDTO[] = $state([]); const commentsBase = $derived( annotationId @@ -76,13 +82,15 @@ async function postComment() { if (!text || posting) return; posting = true; try { + const { content, mentionedUserIds } = extractContent(text, newMentionCandidates); const res = await fetch(commentsBase, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ content: text }) + body: JSON.stringify({ content, mentionedUserIds }) }); if (res.ok) { newText = ''; + newMentionCandidates = []; await reload(); } } finally { @@ -95,13 +103,15 @@ async function postReply(threadId: string) { if (!text || posting) return; posting = true; try { + const { content, mentionedUserIds } = extractContent(text, replyMentionCandidates); const res = await fetch(`${commentsBase}/${threadId}/replies`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ content: text }) + body: JSON.stringify({ content, mentionedUserIds }) }); if (res.ok) { replyText = ''; + replyMentionCandidates = []; replyingTo = null; await reload(); } @@ -115,13 +125,15 @@ async function saveEdit(commentId: string) { if (!text || posting) return; posting = true; try { + const { content, mentionedUserIds } = extractContent(text, editMentionCandidates); const res = await fetch(`/api/documents/${documentId}/comments/${commentId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ content: text }) + body: JSON.stringify({ content, mentionedUserIds }) }); if (res.ok) { editingId = null; + editMentionCandidates = []; await reload(); } } finally { @@ -147,6 +159,7 @@ async function deleteComment(commentId: string) { function startEdit(comment: Comment | CommentReply) { editingId = comment.id; editText = comment.content; + editMentionCandidates = []; } function cancelEdit() { @@ -181,11 +194,13 @@ onMount(() => { {#snippet commentEntry(comment: Comment | CommentReply, threadId: string, showReplyButton: boolean)} {#if editingId === comment.id}
{comment.content}
++ + {@html renderBody(comment.content, comment.mentionDTOs ?? [])} +