mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: implement editor preview functionality
This commit is contained in:
parent
5b2187c311
commit
0a38f5bda7
4 changed files with 17 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ import { getActivity } from "@services/courses/activities";
|
||||||
import AuthProvider from "@components/Security/AuthProvider";
|
import AuthProvider from "@components/Security/AuthProvider";
|
||||||
import EditorWrapper from "@components/Editor/EditorWrapper";
|
import EditorWrapper from "@components/Editor/EditorWrapper";
|
||||||
import useSWR, { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
import { getAPIUrl } from "@services/config/config";
|
import { getAPIUrl, getOrgFromUri } from "@services/config/config";
|
||||||
import { swrFetcher } from "@services/utils/ts/requests";
|
import { swrFetcher } from "@services/utils/ts/requests";
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -16,15 +16,18 @@ function EditActivity(params: any) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const activityid = params.params.activityid;
|
const activityid = params.params.activityid;
|
||||||
const courseid = params.params.courseid;
|
const courseid = params.params.courseid;
|
||||||
|
const orgslug = params.params.orgslug;
|
||||||
const { data: courseInfo, error: error_course } = useSWR(`${getAPIUrl()}courses/meta/course_${courseid}`, swrFetcher);
|
const { data: courseInfo, error: error_course } = useSWR(`${getAPIUrl()}courses/meta/course_${courseid}`, swrFetcher);
|
||||||
const { data: activity, error: error_activity } = useSWR(`${getAPIUrl()}activities/activity_${activityid}`, swrFetcher);
|
const { data: activity, error: error_activity } = useSWR(`${getAPIUrl()}activities/activity_${activityid}`, swrFetcher);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
{!courseInfo || !activity ? <div>Loading...</div> : <EditorWrapper course={courseInfo} activity={activity} content={activity.content}></EditorWrapper>}
|
{!courseInfo || !activity ? <div>Loading...</div> : <EditorWrapper orgslug={orgslug} course={courseInfo} activity={activity} content={activity.content}></EditorWrapper>}
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { ToolbarButtons } from "./Toolbar/ToolbarButtons";
|
||||||
import { motion, AnimatePresence } from "framer-motion";
|
import { motion, AnimatePresence } from "framer-motion";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { getBackendUrl } from "@services/config/config";
|
import { getBackendUrl, getUriWithOrg } from "@services/config/config";
|
||||||
import { DividerVerticalIcon, EyeOpenIcon, SlashIcon } from "@radix-ui/react-icons";
|
import { DividerVerticalIcon, EyeOpenIcon, SlashIcon } from "@radix-ui/react-icons";
|
||||||
import Avvvatars from "avvvatars-react";
|
import Avvvatars from "avvvatars-react";
|
||||||
// extensions
|
// extensions
|
||||||
|
|
@ -23,18 +23,25 @@ import MathEquationBlock from "./Extensions/MathEquation/MathEquationBlock";
|
||||||
import PDFBlock from "./Extensions/PDF/PDFBlock";
|
import PDFBlock from "./Extensions/PDF/PDFBlock";
|
||||||
import QuizBlock from "./Extensions/Quiz/QuizBlock";
|
import QuizBlock from "./Extensions/Quiz/QuizBlock";
|
||||||
import ToolTip from "@components/UI/Tooltip/Tooltip";
|
import ToolTip from "@components/UI/Tooltip/Tooltip";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
interface Editor {
|
interface Editor {
|
||||||
content: string;
|
content: string;
|
||||||
ydoc: any;
|
ydoc: any;
|
||||||
provider: any;
|
provider: any;
|
||||||
activity: any;
|
activity: any;
|
||||||
|
orgslug : string
|
||||||
course: any;
|
course: any;
|
||||||
setContent: (content: string) => void;
|
setContent: (content: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Editor(props: Editor) {
|
function Editor(props: Editor) {
|
||||||
const auth: any = React.useContext(AuthContext);
|
const auth: any = React.useContext(AuthContext);
|
||||||
|
// remove course_ from course_id
|
||||||
|
const course_id = props.course.course.course_id.substring(7);
|
||||||
|
|
||||||
|
// remove activity_ from activity_id
|
||||||
|
const activity_id = props.activity.activity_id.substring(9);
|
||||||
|
|
||||||
const editor: any = useEditor({
|
const editor: any = useEditor({
|
||||||
editable: true,
|
editable: true,
|
||||||
|
|
@ -128,7 +135,7 @@ function Editor(props: Editor) {
|
||||||
<DividerVerticalIcon style={{ marginTop: "auto", marginBottom: "auto", color: "grey" }} />
|
<DividerVerticalIcon style={{ marginTop: "auto", marginBottom: "auto", color: "grey" }} />
|
||||||
<EditorLeftOptionsSection>
|
<EditorLeftOptionsSection>
|
||||||
<EditorLeftOptionsSaveButton onClick={() => props.setContent(editor.getJSON())}> Save </EditorLeftOptionsSaveButton>
|
<EditorLeftOptionsSaveButton onClick={() => props.setContent(editor.getJSON())}> Save </EditorLeftOptionsSaveButton>
|
||||||
<ToolTip content="Preview"><EditorLeftOptionsPreviewButton> <Eye size={15} /> </EditorLeftOptionsPreviewButton></ToolTip>
|
<ToolTip content="Preview"><Link target="_blank" href={`/course/${course_id}/activity/${activity_id}`}><EditorLeftOptionsPreviewButton> <Eye size={15} /> </EditorLeftOptionsPreviewButton></Link></ToolTip>
|
||||||
</EditorLeftOptionsSection>
|
</EditorLeftOptionsSection>
|
||||||
</EditorUsersSection>
|
</EditorUsersSection>
|
||||||
</EditorTop>
|
</EditorTop>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ interface EditorWrapperProps {
|
||||||
content: string;
|
content: string;
|
||||||
activity: any;
|
activity: any;
|
||||||
course:any
|
course:any
|
||||||
|
orgslug: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function EditorWrapper(props: EditorWrapperProps) : JSX.Element {
|
function EditorWrapper(props: EditorWrapperProps) : JSX.Element {
|
||||||
|
|
@ -35,7 +36,7 @@ function EditorWrapper(props: EditorWrapperProps) : JSX.Element {
|
||||||
createRTCProvider();
|
createRTCProvider();
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
} else {
|
} else {
|
||||||
return <Editor course={props.course} activity={props.activity} content={props.content} setContent={setContent} provider={providerState} ydoc={ydocState}></Editor>;
|
return <Editor orgslug={props.orgslug} course={props.course} activity={props.activity} content={props.content} setContent={setContent} provider={providerState} ydoc={ydocState}></Editor>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ async def get_course_meta(request: Request, course_id: str, current_user: Public
|
||||||
for chapter in chapters:
|
for chapter in chapters:
|
||||||
chapters_list_with_activities.append(
|
chapters_list_with_activities.append(
|
||||||
{"id": chapters[chapter]["id"], "name": chapters[chapter]["name"], "activities": [activities_list[activity] for activity in chapters[chapter]["activityIds"]]})
|
{"id": chapters[chapter]["id"], "name": chapters[chapter]["name"], "activities": [activities_list[activity] for activity in chapters[chapter]["activityIds"]]})
|
||||||
course = Course(**course)
|
course = CourseInDB(**course)
|
||||||
|
|
||||||
# Get activity by user
|
# Get activity by user
|
||||||
trail = await trails.find_one(
|
trail = await trails.find_one(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue