mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init editor + collaboration
This commit is contained in:
parent
8ca7d9fc1a
commit
85ac404ee7
10 changed files with 1437 additions and 12 deletions
33
front/components/editor/Editor.tsx
Normal file
33
front/components/editor/Editor.tsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { default as React, useEffect, useRef } from "react";
|
||||
import * as Y from "yjs";
|
||||
import { WebrtcProvider } from "y-webrtc";
|
||||
import EditorWithOptions from "./EditorWithOptions";
|
||||
|
||||
// tools
|
||||
|
||||
function Editor() {
|
||||
// A new Y document
|
||||
const ydoc = new Y.Doc();
|
||||
const [providerState, setProviderState] = React.useState<any>({});
|
||||
const [ydocState, setYdocState] = React.useState<any>({});
|
||||
const [isLoading, setIsLoading] = React.useState(true);
|
||||
|
||||
function createRTCProvider() {
|
||||
const provider = new WebrtcProvider("learnhouse-1", ydoc);
|
||||
setYdocState(ydoc);
|
||||
setProviderState(provider);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
createRTCProvider();
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
<EditorWithOptions provider={providerState} ydoc={ydocState}></EditorWithOptions>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Editor;
|
||||
Loading…
Add table
Add a link
Reference in a new issue