{thread.root.author} {thread.root.contents}
{thread.replies.map((reply) => ({reply.author} {reply.contents}
))} {comments.canReply(thread.root.ref) && ( )}import { useState } from 'react';
import { Viewer, DocumentGate } from '@embedpdf/react/runtime';
import type { OpenInput } from '@embedpdf/react/runtime';
import { Stage, stagePlugin, useStage } 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,
annotationKey,
annotationPlugin,
useAnnotation,
useAnnotationState,
useComments,
useCommentThreads,
type CommentThreadView,
} from '@embedpdf/react/annotation';
import { cloudEngine } from '@cloudpdf/engine';
import './comments.css';
const engine = cloudEngine();
const plugins = [
stagePlugin(),
renderPlugin(),
interactionPlugin(),
selectionPlugin(),
annotationPlugin(),
];
const proposal: OpenInput = { kind: 'grant', grant: 'shr_qnqHtCNRpzz-s7DPFBIbuOAF' };
// One thread: the first comment, its replies, a reply box, and a button that shows it.
function Thread({ thread }: { thread: CommentThreadView }) {
const comments = useComments();
const annotation = useAnnotation();
const stage = useStage();
const [text, setText] = useState('');
function show() {
stage.reveal(thread.page, { rect: thread.root.rect });
annotation.selection.select([thread.root.ref]); // and select it
}
return (
{thread.root.author} {thread.root.contents}
{reply.author} {reply.contents}
Loading comments…
} {!loading && threads.length === 0 &&No comments
} {threads.map((thread) => (