mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
'use client';
|
|
import { default as React, } from "react";
|
|
import * as Y from "yjs";
|
|
import Editor from "./Editor";
|
|
import { updateActivity } from "@services/courses/activities";
|
|
import { toast } from "react-hot-toast";
|
|
import Toast from "@components/StyledElements/Toast/Toast";
|
|
|
|
interface EditorWrapperProps {
|
|
content: string;
|
|
activity: any;
|
|
course: any
|
|
orgslug: string;
|
|
org: any;
|
|
}
|
|
|
|
function EditorWrapper(props: EditorWrapperProps): JSX.Element {
|
|
// 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.activity.activity_id, ydoc);
|
|
// setYdocState(ydoc);
|
|
// setProviderState(provider);
|
|
setIsLoading(false);
|
|
}
|
|
|
|
|
|
|
|
async function setContent(content: any) {
|
|
let activity = props.activity;
|
|
activity.content = content;
|
|
|
|
toast.promise(
|
|
updateActivity(activity, activity.activity_id),
|
|
{
|
|
loading: 'Saving...',
|
|
success: <b>Activity saved!</b>,
|
|
error: <b>Could not save.</b>,
|
|
}
|
|
);
|
|
}
|
|
|
|
if (isLoading) {
|
|
createRTCProvider();
|
|
return <div>Loading...</div>;
|
|
} else {
|
|
return <>
|
|
<Toast></Toast>
|
|
<Editor org={props.org} orgslug={props.orgslug} course={props.course} activity={props.activity} content={props.content} setContent={setContent} provider={providerState} ydoc={ydocState}></Editor>;
|
|
|
|
</>
|
|
}
|
|
}
|
|
|
|
export default EditorWrapper;
|