{thread.root.author} {thread.root.contents}
{thread.replies.map((each) => ({each.author} {each.contents}
))} {comments.canReply(thread.root.ref) && ( )}import { useEffect, useState } from 'react';
import { Viewer, DocumentGate } from '@embedpdf/react/runtime';
import type { OpenInput } from '@embedpdf/react/runtime';
import { Stage, stagePlugin } from '@embedpdf/react/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/react/render';
import { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection';
import { interactionPlugin } from '@embedpdf/react/interaction';
import {
AnnotationLayer,
AnnotationMenu,
annotationKey,
annotationPlugin,
useAnnotation,
useAnnotationState,
useCommentThread,
useComments,
} from '@embedpdf/react/annotation';
import { cloudEngine } from '@cloudpdf/engine';
import './note-card.css';
const engine = cloudEngine();
const plugins = [
stagePlugin(),
renderPlugin(),
interactionPlugin(),
selectionPlugin(),
annotationPlugin(),
];
const proposal: OpenInput = { kind: 'grant', grant: 'shr_qnqHtCNRpzz-s7DPFBIbuOAF' };
// The clicked annotation's comment and its replies, in your own card next to it: a note, or any
// mark that carries a comment, such as a highlight. It shows while the annotation is selected.
function NoteCard() {
const annotation = useAnnotation();
const comments = useComments();
const { selected } = useAnnotationState();
const thread = useCommentThread(selected.length === 1 ? selected[0]!.ref : null);
const [reply, setReply] = useState('');
// Escape closes the card, as it ends the selection.
useEffect(() => {
const close = (event: KeyboardEvent) => {
if (event.key === 'Escape') annotation.selection.clear();
};
window.addEventListener('keydown', close);
return () => window.removeEventListener('keydown', close);
}, [annotation]);
if (!thread?.root.contents) return null; // no comment to read
return (
{thread.root.author} {thread.root.contents}
{each.author} {each.contents}
Click the note next to the title, or the highlighted sentence