@@ -6,36 +6,45 @@ import "@blocknote/mantine/style.css";
66import { useCreateBlockNote } from "@blocknote/react" ;
77import { HocuspocusProvider } from "@hocuspocus/provider" ;
88
9+ // Hardcoded settings for demo purposes
910const USER_ID = "user123" ;
1011const USER_ROLE : "COMMENT-ONLY" | "READ-WRITE" = "READ-WRITE" ;
1112const DOCUMENT_ID = "mydoc123" ;
1213const TOKEN = `${ USER_ID } __${ USER_ROLE } ` ;
1314
15+ // Setup Hocuspocus provider
1416const provider = new HocuspocusProvider ( {
1517 url : "ws://localhost:8787/hocuspocus" ,
1618 token : TOKEN ,
1719 name : DOCUMENT_ID ,
1820} ) ;
1921
20- // const threadStore = new YjsThreadStore(
21- // "123",
22- // provider.document.getMap("threads"),
23- // new DefaultThreadStoreAuth("123", "editor")
24- // );
22+ // The thread store auth is used by the BlockNote interface to determine which actions are allowed
23+ // (and which elements should be shown)
24+ const threadStoreAuth = new DefaultThreadStoreAuth (
25+ USER_ID ,
26+ USER_ROLE === "READ-WRITE" ? "editor" : "comment"
27+ ) ;
2528
26- debugger ;
29+ // set up the thread store using the REST API
2730const threadStore = new RESTYjsThreadStore (
2831 `http://localhost:8787/documents/${ DOCUMENT_ID } /threads` ,
2932 {
3033 Authorization : `Bearer ${ TOKEN } ` ,
3134 } ,
3235 provider . document . getMap ( "threads" ) ,
33- new DefaultThreadStoreAuth (
34- USER_ID ,
35- USER_ROLE === "READ-WRITE" ? "editor" : "comment"
36- )
36+ threadStoreAuth
3737) ;
3838
39+ // Instead of using the REST API, you could also use a YjsThreadStore
40+ // however, this lacks good authentication on comment operations
41+ //
42+ // const threadStore = new YjsThreadStore(
43+ // USER_ID,
44+ // provider.document.getMap("threads"),
45+ // threadStoreAuth
46+ // );
47+
3948// Our <Editor> component we can reuse later
4049export default function Editor ( ) {
4150 // Creates a new editor instance.
0 commit comments