mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: refactor files
feat: refactor more files feat: uppercase component folder 1/2 feat: uppercase component folder 2/2
This commit is contained in:
parent
a371394670
commit
d361e68dc0
31 changed files with 101 additions and 117 deletions
|
|
@ -1,46 +0,0 @@
|
|||
import { default as React, useEffect, useRef } from "react";
|
||||
import * as Y from "yjs";
|
||||
import { WebrtcProvider } from "y-webrtc";
|
||||
import EditorWithOptions from "./EditorWithOptions";
|
||||
import { IndexeddbPersistence } from "y-indexeddb";
|
||||
import { updateElement } from "../../services/courses/elements";
|
||||
|
||||
interface EditorProps {
|
||||
content: string;
|
||||
element: any;
|
||||
}
|
||||
|
||||
function Editor(props: EditorProps) {
|
||||
// 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(props.element.element_id, ydoc);
|
||||
|
||||
setYdocState(ydoc);
|
||||
setProviderState(provider);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function setContent(content: any) {
|
||||
let element = props.element;
|
||||
element.content = content;
|
||||
const res = await updateElement(element, element.element_id);
|
||||
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
createRTCProvider();
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
<EditorWithOptions content={props.content} setContent={setContent} provider={providerState} ydoc={ydocState}></EditorWithOptions>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Editor;
|
||||
Loading…
Add table
Add a link
Reference in a new issue