feat: rename lectures to activities across the app

This commit is contained in:
swve 2023-03-23 22:57:36 +01:00
parent bc2def6178
commit 7b63eb573c
51 changed files with 570 additions and 570 deletions

View file

@ -4,7 +4,7 @@ import { default as React, useEffect, useRef } from "react";
import { useRouter } from "next/navigation";
import { getLecture } from "@services/courses/lectures";
import { getActivity } from "@services/courses/activities";
import AuthProvider from "@components/Security/AuthProvider";
import EditorWrapper from "@components/Editor/EditorWrapper";
import useSWR, { mutate } from "swr";
@ -12,21 +12,21 @@ import { getAPIUrl } from "@services/config/config";
import { swrFetcher } from "@services/utils/requests";
function EditLecture(params: any) {
function EditActivity(params: any) {
const router = useRouter();
const lectureid = params.params.lectureid;
const activityid = params.params.activityid;
const courseid = params.params.courseid;
const { data: courseInfo, error: error_course } = useSWR(`${getAPIUrl()}courses/meta/course_${courseid}`, swrFetcher);
const { data: lecture, error: error_lecture } = useSWR(`${getAPIUrl()}lectures/lecture_${lectureid}`, swrFetcher);
const { data: activity, error: error_activity } = useSWR(`${getAPIUrl()}activities/activity_${activityid}`, swrFetcher);
return (
<AuthProvider>
{!courseInfo || !lecture ? <div>Loading...</div> : <EditorWrapper course={courseInfo} lecture={lecture} content={lecture.content}></EditorWrapper>}
{!courseInfo || !activity ? <div>Loading...</div> : <EditorWrapper course={courseInfo} activity={activity} content={activity.content}></EditorWrapper>}
</AuthProvider>
);
}
export default EditLecture;
export default EditActivity;

View file

@ -3,61 +3,61 @@ import { useRouter } from "next/navigation";
import Link from "next/link";
import React, { useMemo } from "react";
import Layout from "@components/UI/Layout";
import { getLecture } from "@services/courses/lectures";
import { getActivity } from "@services/courses/activities";
import { getAPIUrl, getBackendUrl, getUriWithOrg } from "@services/config/config";
import Canva from "@components/LectureViews/DynamicCanva/DynamicCanva";
import styled from "styled-components";
import Canva from "@components/ActivityViews/DynamicCanva/DynamicCanva";
import styled from "styled-components";
import { getCourse } from "@services/courses/courses";
import VideoLecture from "@components/LectureViews/Video/Video";
import VideoActivity from "@components/ActivityViews/Video/Video";
import useSWR, { mutate } from "swr";
import { Check } from "lucide-react";
import { maskLectureAsComplete } from "@services/courses/activity";
import { maskActivityAsComplete } from "@services/courses/activity";
import { swrFetcher } from "@services/utils/requests";
function LecturePage(params: any) {
const lectureid = params.params.lectureid;
function ActivityPage(params: any) {
const activityid = params.params.activityid;
const courseid = params.params.courseid;
const orgslug = params.params.orgslug;
const { data: course, error: error_course } = useSWR(`${getAPIUrl()}courses/meta/course_${courseid}`, swrFetcher);
const { data: lecture, error: error_lecture } = useSWR(`${getAPIUrl()}lectures/lecture_${lectureid}`, swrFetcher);
const { data: activity, error: error_activity } = useSWR(`${getAPIUrl()}activities/activity_${activityid}`, swrFetcher);
console.log(course, lecture);
console.log(course, activity);
async function markLectureAsCompleteFront() {
const activity = await maskLectureAsComplete("" + lectureid, courseid, lecture.lecture_id.replace("lecture_", ""));
mutate(`${getAPIUrl()}lectures/lecture_${lectureid}`);
async function markActivityAsCompleteFront() {
const activity = await maskActivityAsComplete("" + activityid, courseid, activity.activity_id.replace("activity_", ""));
mutate(`${getAPIUrl()}activities/activity_${activityid}`);
mutate(`${getAPIUrl()}courses/meta/course_${courseid}`);
}
return (
<>
{error_course && <p>Failed to load</p>}
{!course || !lecture ? (
{!course || !activity ? (
<div>Loading...</div>
) : (
<LectureLayout>
<LectureTopWrapper>
<LectureThumbnail>
<ActivityLayout>
<ActivityTopWrapper>
<ActivityThumbnail>
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}`}>
<img src={`${getBackendUrl()}content/uploads/img/${course.course.thumbnail}`} alt="" />
</Link>
</LectureThumbnail>
<LectureInfo>
</ActivityThumbnail>
<ActivityInfo>
<p>Course</p>
<h1>{course.course.name}</h1>
</LectureInfo>
</LectureTopWrapper>
</ActivityInfo>
</ActivityTopWrapper>
<ChaptersWrapper>
{course.chapters.map((chapter: any) => {
return (
<>
<div style={{ display: "flex", flexDirection: "row" }} key={chapter.chapter_id}>
{chapter.lectures.map((lecture: any) => {
{chapter.activities.map((activity: any) => {
return (
<>
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/lecture/${lecture.id.replace("lecture_", "")}`}>
<ChapterIndicator key={lecture.id} />
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/activity/${activity.id.replace("activity_", "")}`}>
<ChapterIndicator key={activity.id} />
</Link>{" "}
</>
);
@ -69,15 +69,15 @@ function LecturePage(params: any) {
})}
</ChaptersWrapper>
{lecture ? (
{activity ? (
<CourseContent>
{lecture.type == "dynamic" && <Canva content={lecture.content} lecture={lecture} />}
{activity.type == "dynamic" && <Canva content={activity.content} activity={activity} />}
{/* todo : use apis & streams instead of this */}
{lecture.type == "video" && <VideoLecture course={course} lecture={lecture} />}
{activity.type == "video" && <VideoActivity course={course} activity={activity} />}
<ActivityMarkerWrapper>
{course.activity.lectures_marked_complete &&
course.activity.lectures_marked_complete.includes("lecture_" + lectureid) &&
{course.activity.activities_marked_complete &&
course.activity.activities_marked_complete.includes("activity_" + activityid) &&
course.activity.status == "ongoing" ? (
<button style={{ backgroundColor: "green" }}>
<i>
@ -86,7 +86,7 @@ function LecturePage(params: any) {
Already completed
</button>
) : (
<button onClick={markLectureAsCompleteFront}>
<button onClick={markActivityAsCompleteFront}>
{" "}
<i>
<Check size={20}></Check>
@ -99,15 +99,15 @@ function LecturePage(params: any) {
) : (
<div>Loading...</div>
)}
</LectureLayout>
</ActivityLayout>
)}
</>
);
}
const LectureLayout = styled.div``;
const ActivityLayout = styled.div``;
const LectureThumbnail = styled.div`
const ActivityThumbnail = styled.div`
padding-right: 30px;
justify-self: center;
img {
@ -117,7 +117,7 @@ const LectureThumbnail = styled.div`
height: 57px;
}
`;
const LectureInfo = styled.div`
const ActivityInfo = styled.div`
h1 {
margin-top: 0px;
}
@ -158,7 +158,7 @@ const ChapterIndicator = styled.div`
}
`;
const LectureTopWrapper = styled.div`
const ActivityTopWrapper = styled.div`
width: 1300px;
padding-top: 50px;
margin: 0 auto;
@ -215,4 +215,4 @@ const ActivityMarkerWrapper = styled.div`
}
`;
export default LecturePage;
export default ActivityPage;

View file

@ -11,8 +11,8 @@ import Chapter from "@components/Drags/Chapter";
import { createChapter, deleteChapter, getCourseChaptersMetadata, updateChaptersMetadata } from "@services/courses/chapters";
import { useRouter } from "next/navigation";
import NewChapterModal from "@components/Modals/CourseEdit/NewChapter";
import NewLectureModal from "@components/Modals/CourseEdit/NewLecture";
import { createLecture, createFileLecture } from "@services/courses/lectures";
import NewActivityModal from "@components/Modals/CourseEdit/NewActivity";
import { createActivity, createFileActivity } from "@services/courses/activities";
import { getOrganizationContextInfo } from "@services/organizations/orgs";
function CourseEdit(params: any) {
@ -23,9 +23,9 @@ function CourseEdit(params: any) {
// New Chapter Modal State
const [newChapterModal, setNewChapterModal] = useState(false) as any;
// New Lecture Modal State
const [newLectureModal, setNewLectureModal] = useState(false) as any;
const [newLectureModalData, setNewLectureModalData] = useState("") as any;
// New Activity Modal State
const [newActivityModal, setNewActivityModal] = useState(false) as any;
const [newActivityModalData, setNewActivityModalData] = useState("") as any;
// Check window availability
const [winReady, setwinReady] = useState(false);
@ -53,16 +53,16 @@ function CourseEdit(params: any) {
const chapterOrder = data.chapterOrder ? data.chapterOrder : [];
return chapterOrder.map((chapterId: any) => {
const chapter = data.chapters[chapterId];
let lectures = [];
if (data.lectures) {
lectures = chapter.lectureIds.map((lectureId: any) => data.lectures[lectureId])
? chapter.lectureIds.map((lectureId: any) => data.lectures[lectureId])
let activities = [];
if (data.activities) {
activities = chapter.activityIds.map((activityId: any) => data.activities[activityId])
? chapter.activityIds.map((activityId: any) => data.activities[activityId])
: [];
}
return {
list: {
chapter: chapter,
lectures: lectures,
activities: activities,
},
};
});
@ -75,23 +75,23 @@ function CourseEdit(params: any) {
setNewChapterModal(false);
};
// Submit new lecture
const submitLecture = async (lecture: any) => {
console.log("submitLecture", lecture);
// Submit new activity
const submitActivity = async (activity: any) => {
console.log("submitActivity", activity);
let org = await getOrganizationContextInfo(orgslug);
await updateChaptersMetadata(courseid, data);
await createLecture(lecture, lecture.chapterId, org.org_id);
await createActivity(activity, activity.chapterId, org.org_id);
await getCourseChapters();
setNewLectureModal(false);
setNewActivityModal(false);
};
// Submit File Upload
const submitFileLecture = async (file: any, type: any, lecture: any, chapterId: string) => {
console.log("submitFileLecture", file);
const submitFileActivity = async (file: any, type: any, activity: any, chapterId: string) => {
console.log("submitFileActivity", file);
await updateChaptersMetadata(courseid, data);
await createFileLecture(file, type, lecture, chapterId);
await createFileActivity(file, type, activity, chapterId);
await getCourseChapters();
setNewLectureModal(false);
setNewActivityModal(false);
};
const deleteChapterUI = async (chapterId: any) => {
@ -111,10 +111,10 @@ function CourseEdit(params: any) {
*/
const openNewLectureModal = async (chapterId: any) => {
console.log("openNewLectureModal", chapterId);
setNewLectureModal(true);
setNewLectureModalData(chapterId);
const openNewActivityModal = async (chapterId: any) => {
console.log("openNewActivityModal", chapterId);
setNewActivityModal(true);
setNewActivityModalData(chapterId);
};
// Close new chapter modal
@ -122,8 +122,8 @@ function CourseEdit(params: any) {
setNewChapterModal(false);
};
const closeNewLectureModal = () => {
setNewLectureModal(false);
const closeNewActivityModal = () => {
setNewActivityModal(false);
};
/*
@ -134,12 +134,12 @@ function CourseEdit(params: any) {
const { destination, source, draggableId, type } = result;
console.log(result);
// check if the lecture is dropped outside the droppable area
// check if the activity is dropped outside the droppable area
if (!destination) {
return;
}
// check if the lecture is dropped in the same place
// check if the activity is dropped in the same place
if (destination.droppableId === source.droppableId && destination.index === source.index) {
return;
}
@ -159,26 +159,26 @@ function CourseEdit(params: any) {
return;
}
//////////////////////// LECTURES IN SAME CHAPTERS ////////////////////////////
// check if the lecture is dropped in the same chapter
//////////////////////// ACTIVITIES IN SAME CHAPTERS ////////////////////////////
// check if the activity is dropped in the same chapter
const start = data.chapters[source.droppableId];
const finish = data.chapters[destination.droppableId];
// check if the lecture is dropped in the same chapter
// check if the activity is dropped in the same chapter
if (start === finish) {
// create new arrays for chapters and lectures
// create new arrays for chapters and activities
const chapter = data.chapters[source.droppableId];
const newLectureIds = Array.from(chapter.lectureIds);
const newActivityIds = Array.from(chapter.activityIds);
// remove the lecture from the old position
newLectureIds.splice(source.index, 1);
// remove the activity from the old position
newActivityIds.splice(source.index, 1);
// add the lecture to the new position
newLectureIds.splice(destination.index, 0, draggableId);
// add the activity to the new position
newActivityIds.splice(destination.index, 0, draggableId);
const newChapter = {
...chapter,
lectureIds: newLectureIds,
activityIds: newActivityIds,
};
const newState = {
@ -193,25 +193,25 @@ function CourseEdit(params: any) {
return;
}
//////////////////////// LECTURES IN DIFF CHAPTERS ////////////////////////////
// check if the lecture is dropped in a different chapter
//////////////////////// ACTIVITIES IN DIFF CHAPTERS ////////////////////////////
// check if the activity is dropped in a different chapter
if (start !== finish) {
// create new arrays for chapters and lectures
const startChapterLectureIds = Array.from(start.lectureIds);
// create new arrays for chapters and activities
const startChapterActivityIds = Array.from(start.activityIds);
// remove the lecture from the old position
startChapterLectureIds.splice(source.index, 1);
// remove the activity from the old position
startChapterActivityIds.splice(source.index, 1);
const newStart = {
...start,
lectureIds: startChapterLectureIds,
activityIds: startChapterActivityIds,
};
// add the lecture to the new position within the chapter
const finishChapterLectureIds = Array.from(finish.lectureIds);
finishChapterLectureIds.splice(destination.index, 0, draggableId);
// add the activity to the new position within the chapter
const finishChapterActivityIds = Array.from(finish.activityIds);
finishChapterActivityIds.splice(destination.index, 0, draggableId);
const newFinish = {
...finish,
lectureIds: finishChapterLectureIds,
activityIds: finishChapterActivityIds,
};
const newState = {
@ -249,13 +249,13 @@ function CourseEdit(params: any) {
</button>
</Title>
{newChapterModal && <NewChapterModal closeModal={closeNewChapterModal} submitChapter={submitChapter}></NewChapterModal>}
{newLectureModal && (
<NewLectureModal
closeModal={closeNewLectureModal}
submitFileLecture={submitFileLecture}
submitLecture={submitLecture}
chapterId={newLectureModalData}
></NewLectureModal>
{newActivityModal && (
<NewActivityModal
closeModal={closeNewActivityModal}
submitFileActivity={submitFileActivity}
submitActivity={submitActivity}
chapterId={newActivityModalData}
></NewActivityModal>
)}
<br />
@ -271,7 +271,7 @@ function CourseEdit(params: any) {
<Chapter
orgslug={orgslug}
courseid={courseid}
openNewLectureModal={openNewLectureModal}
openNewActivityModal={openNewActivityModal}
deleteChapter={deleteChapterUI}
key={index}
info={info}

View file

@ -53,10 +53,10 @@ const CourseIdPage = (params: any) => {
{course.chapters.map((chapter: any) => {
return (
<>
{chapter.lectures.map((lecture: any) => {
{chapter.activities.map((activity: any) => {
return (
<>
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/lecture/${lecture.id.replace("lecture_", "")}`}>
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/activity/${activity.id.replace("activity_", "")}`}>
<ChapterIndicator />
</Link>{" "}
</>
@ -92,12 +92,12 @@ const CourseIdPage = (params: any) => {
return (
<>
<h3>Chapter : {chapter.name}</h3>
{chapter.lectures.map((lecture: any) => {
{chapter.activities.map((activity: any) => {
return (
<>
<p>
Lecture {lecture.name}
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/lecture/${lecture.id.replace("lecture_", "")}`} rel="noopener noreferrer">
Activity {activity.name}
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/activity/${activity.id.replace("activity_", "")}`} rel="noopener noreferrer">
<EyeOpenIcon />
</Link>{" "}
</p>

View file

@ -13,7 +13,7 @@ import PDFBlock from "@components/Editor/Extensions/PDF/PDFBlock";
interface Editor {
content: string;
lecture: any;
activity: any;
//course: any;
}
@ -32,19 +32,19 @@ function Canva(props: Editor) {
}),
ImageBlock.configure({
editable: isEditable,
lecture: props.lecture,
activity: props.activity,
}),
VideoBlock.configure({
editable: true,
lecture: props.lecture,
activity: props.activity,
}),
MathEquationBlock.configure({
editable: false,
lecture: props.lecture,
activity: props.activity,
}),
PDFBlock.configure({
editable: true,
lecture: props.lecture,
activity: props.activity,
}),
Youtube.configure({
controls: true,

View file

@ -2,10 +2,10 @@ import { getBackendUrl } from "@services/config/config";
import React from "react";
import styled from "styled-components";
function VideoLecture({ lecture, course }: { lecture: any; course: any }) {
function VideoActivity({ activity, course }: { activity: any; course: any }) {
function getChapterName() {
let chapterName = "";
let chapterId = lecture.chapter_id;
let chapterId = activity.chapter_id;
course.chapters.forEach((chapter: any) => {
if (chapter.chapter_id === chapterId) {
chapterName = chapter.name;
@ -15,21 +15,21 @@ function VideoLecture({ lecture, course }: { lecture: any; course: any }) {
}
return (
<VideoLectureLayout>
<VideoActivityLayout>
<VideoTitle>
<p>Chapter : {getChapterName()}</p>
{lecture.name}
{activity.name}
</VideoTitle>
<VideoPlayerWrapper>
<video controls src={`${getBackendUrl()}content/uploads/video/${lecture.content.video.lecture_id}/${lecture.content.video.filename}`}></video>
<video controls src={`${getBackendUrl()}content/uploads/video/${activity.content.video.activity_id}/${activity.content.video.filename}`}></video>
</VideoPlayerWrapper>
</VideoLectureLayout>
</VideoActivityLayout>
);
}
export default VideoLecture;
export default VideoActivity;
const VideoLectureLayout = styled.div`
const VideoActivityLayout = styled.div`
display: flex;
flex-direction: column;
margin-top: 10px;

View file

@ -5,31 +5,31 @@ import { EyeOpenIcon, Pencil2Icon } from '@radix-ui/react-icons'
import styled from "styled-components";
import { getUriWithOrg } from "@services/config/config";
function Lecture(props: any) {
function Activity(props: any) {
return (
<Draggable key={props.lecture.id} draggableId={props.lecture.id} index={props.index}>
<Draggable key={props.activity.id} draggableId={props.activity.id} index={props.index}>
{(provided) => (
<LectureWrapper key={props.lecture.id} {...provided.draggableProps} {...provided.dragHandleProps} ref={provided.innerRef}>
<p>{props.lecture.name} </p>
<ActivityWrapper key={props.activity.id} {...provided.draggableProps} {...provided.dragHandleProps} ref={provided.innerRef}>
<p>{props.activity.name} </p>
<Link
href={getUriWithOrg(props.orgslug,"")+`/course/${props.courseid}/lecture/${props.lecture.id.replace("lecture_", "")}`}
href={getUriWithOrg(props.orgslug,"")+`/course/${props.courseid}/activity/${props.activity.id.replace("activity_", "")}`}
rel="noopener noreferrer">
&nbsp; <EyeOpenIcon/>
</Link>
<Link
href={getUriWithOrg(props.orgslug,"") +`/course/${props.courseid}/lecture/${props.lecture.id.replace("lecture_", "")}/edit`}
href={getUriWithOrg(props.orgslug,"") +`/course/${props.courseid}/activity/${props.activity.id.replace("activity_", "")}/edit`}
rel="noopener noreferrer">
&nbsp; <Pencil2Icon/>
</Link>
</LectureWrapper>
</ActivityWrapper>
)}
</Draggable>
);
}
export const LectureWrapper = styled.div`
export const ActivityWrapper = styled.div`
padding: 2px;
padding-left: 17px;
list-style: none;
@ -44,4 +44,4 @@ export const LectureWrapper = styled.div`
}
`;
export default Lecture;
export default Activity;

View file

@ -1,7 +1,7 @@
import React from "react";
import styled from "styled-components";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import Lecture, { LectureWrapper } from "./Lecture";
import Activity, { ActivityWrapper } from "./Activity";
function Chapter(props: any) {
return (
@ -18,10 +18,10 @@ function Chapter(props: any) {
{props.info.list.chapter.name}{" "}
<button
onClick={() => {
props.openNewLectureModal(props.info.list.chapter.id);
props.openNewActivityModal(props.info.list.chapter.id);
}}
>
Create Lecture
Create Activity
</button>
<button
onClick={() => {
@ -31,14 +31,14 @@ function Chapter(props: any) {
X
</button>
</h3>
<Droppable key={props.info.list.chapter.id} droppableId={props.info.list.chapter.id} type="lecture">
<Droppable key={props.info.list.chapter.id} droppableId={props.info.list.chapter.id} type="activity">
{(provided) => (
<LecturesList {...provided.droppableProps} ref={provided.innerRef}>
{props.info.list.lectures.map((lecture: any, index: any) => (
<Lecture orgslug={props.orgslug} courseid={props.courseid} key={lecture.id} lecture={lecture} index={index}></Lecture>
<ActivitiesList {...provided.droppableProps} ref={provided.innerRef}>
{props.info.list.activities.map((activity: any, index: any) => (
<Activity orgslug={props.orgslug} courseid={props.courseid} key={activity.id} activity={activity} index={index}></Activity>
))}
{provided.placeholder}
</LecturesList>
</ActivitiesList>
)}
</Droppable>
</ChapterWrapper>
@ -66,7 +66,7 @@ const ChapterWrapper = styled.div`
}
`;
const LecturesList = styled.div`
const ActivitiesList = styled.div`
padding: 10px;
`;

View file

@ -1,15 +1,15 @@
export const initialData = {
lectures: {
"lecture-1": { id: "lecture-1", content: "First lecture" },
"lecture-2": { id: "lecture-2", content: "Second lecture" },
"lecture-3": { id: "lecture-3", content: "Third lecture" },
"lecture-4": { id: "lecture-4", content: "Fourth lecture" },
"lecture-5": { id: "lecture-5", content: "Fifth lecture" },
activities: {
"activity-1": { id: "activity-1", content: "First activity" },
"activity-2": { id: "activity-2", content: "Second activity" },
"activity-3": { id: "activity-3", content: "Third activity" },
"activity-4": { id: "activity-4", content: "Fourth activity" },
"activity-5": { id: "activity-5", content: "Fifth activity" },
},
chapters: {
"chapter-1": { id: "chapter-1", name: "Chapter 1", lectureIds: ["lecture-1", "lecture-2", "lecture-3"] },
"chapter-2": { id: "chapter-2", name: "Chapter 2", lectureIds: ["lecture-4"] },
"chapter-3": { id: "chapter-3", name: "Chapter 3", lectureIds: ["lecture-5"] },
"chapter-1": { id: "chapter-1", name: "Chapter 1", activityIds: ["activity-1", "activity-2", "activity-3"] },
"chapter-2": { id: "chapter-2", name: "Chapter 2", activityIds: ["activity-4"] },
"chapter-3": { id: "chapter-3", name: "Chapter 3", activityIds: ["activity-5"] },
},
chapterOrder: ["chapter-1", "chapter-2", "chapter-3"],

View file

@ -28,7 +28,7 @@ interface Editor {
content: string;
ydoc: any;
provider: any;
lecture: any;
activity: any;
course: any;
setContent: (content: string) => void;
}
@ -52,23 +52,23 @@ function Editor(props: Editor) {
}),
ImageBlock.configure({
editable: true,
lecture: props.lecture,
activity: props.activity,
}),
VideoBlock.configure({
editable: true,
lecture: props.lecture,
activity: props.activity,
}),
MathEquationBlock.configure({
editable: true,
lecture: props.lecture,
activity: props.activity,
}),
PDFBlock.configure({
editable: true,
lecture: props.lecture,
activity: props.activity,
}),
QuizBlock.configure({
editable: true,
lecture: props.lecture,
activity: props.activity,
}),
Youtube.configure({
controls: true,
@ -112,7 +112,7 @@ function Editor(props: Editor) {
<EditorInfoThumbnail src={`${getBackendUrl()}content/uploads/img/${props.course.course.thumbnail}`} alt=""></EditorInfoThumbnail>
<EditorInfoDocName>
{" "}
<b>{props.course.course.name}</b> <SlashIcon /> {props.lecture.name}{" "}
<b>{props.course.course.name}</b> <SlashIcon /> {props.activity.name}{" "}
</EditorInfoDocName>
<EditorSaveButton onClick={() => props.setContent(editor.getJSON())}>
Save <Save size={12} />

View file

@ -2,11 +2,11 @@ import { default as React, } from "react";
import * as Y from "yjs";
import { WebrtcProvider } from "y-webrtc";
import Editor from "./Editor";
import { updateLecture } from "../../services/courses/lectures";
import { updateActivity } from "@services/courses/activities";
interface EditorWrapperProps {
content: string;
lecture: any;
activity: any;
course:any
}
@ -18,16 +18,16 @@ function EditorWrapper(props: EditorWrapperProps) : JSX.Element {
const [isLoading, setIsLoading] = React.useState(true);
function createRTCProvider() {
// const provider = new WebrtcProvider(props.lecture.lecture_id, ydoc);
// const provider = new WebrtcProvider(props.activity.activity_id, ydoc);
// setYdocState(ydoc);
// setProviderState(provider);
setIsLoading(false);
}
async function setContent(content: any) {
let lecture = props.lecture;
lecture.content = content;
const res = await updateLecture(lecture, lecture.lecture_id);
let activity = props.activity;
activity.content = content;
const res = await updateActivity(activity, activity.activity_id);
alert(JSON.stringify(res));
}
@ -35,7 +35,7 @@ function EditorWrapper(props: EditorWrapperProps) : JSX.Element {
createRTCProvider();
return <div>Loading...</div>;
} else {
return <Editor course={props.course} lecture={props.lecture} content={props.content} setContent={setContent} provider={providerState} ydoc={ydocState}></Editor>;
return <Editor course={props.course} activity={props.activity} content={props.content} setContent={setContent} provider={providerState} ydoc={ydocState}></Editor>;
}
}

View file

@ -17,7 +17,7 @@ function ImageBlockComponent(props: any) {
const handleSubmit = async (e: any) => {
e.preventDefault();
setIsLoading(true);
let object = await uploadNewImageFile(image, props.extension.options.lecture.lecture_id);
let object = await uploadNewImageFile(image, props.extension.options.activity.activity_id);
setIsLoading(false);
setblockObject(object);
props.updateAttributes({
@ -41,7 +41,7 @@ function ImageBlockComponent(props: any) {
{blockObject && (
<BlockImage>
<img
src={`${getBackendUrl()}content/uploads/files/lectures/${props.extension.options.lecture.lecture_id}/blocks/imageBlock/${blockObject.block_id}/${blockObject.block_data.file_id}.${
src={`${getBackendUrl()}content/uploads/files/activities/${props.extension.options.activity.activity_id}/blocks/imageBlock/${blockObject.block_id}/${blockObject.block_data.file_id}.${
blockObject.block_data.file_format
}`}
alt=""

View file

@ -17,7 +17,7 @@ function PDFBlockComponent(props: any) {
const handleSubmit = async (e: any) => {
e.preventDefault();
setIsLoading(true);
let object = await uploadNewPDFFile(pdf, props.extension.options.lecture.lecture_id);
let object = await uploadNewPDFFile(pdf, props.extension.options.activity.activity_id);
setIsLoading(false);
setblockObject(object);
props.updateAttributes({
@ -41,7 +41,7 @@ function PDFBlockComponent(props: any) {
{blockObject && (
<BlockPDF>
<iframe
src={`${getBackendUrl()}content/uploads/files/lectures/${props.extension.options.lecture.lecture_id}/blocks/pdfBlock/${blockObject.block_id}/${blockObject.block_data.file_id}.${
src={`${getBackendUrl()}content/uploads/files/activities/${props.extension.options.activity.activity_id}/blocks/pdfBlock/${blockObject.block_id}/${blockObject.block_data.file_id}.${
blockObject.block_data.file_format
}`}
/>

View file

@ -88,7 +88,7 @@ function ImageBlockComponent(props: any) {
console.log(questions);
console.log(answers);
try {
let res = await submitQuizBlock(props.extension.options.lecture.lecture_id, {questions : questions , answers : answers})
let res = await submitQuizBlock(props.extension.options.activity.activity_id, {questions : questions , answers : answers})
console.log(res.block_id);
props.updateAttributes({
quizId: {

View file

@ -17,7 +17,7 @@ function VideoBlockComponents(props: any) {
const handleSubmit = async (e: any) => {
e.preventDefault();
setIsLoading(true);
let object = await uploadNewVideoFile(video, props.extension.options.lecture.lecture_id);
let object = await uploadNewVideoFile(video, props.extension.options.activity.activity_id);
setIsLoading(false);
setblockObject(object);
props.updateAttributes({
@ -42,7 +42,7 @@ function VideoBlockComponents(props: any) {
<BlockVideo>
<video
controls
src={`${getBackendUrl()}content/uploads/files/lectures/${props.extension.options.lecture.lecture_id}/blocks/videoBlock/${blockObject.block_id}/${blockObject.block_data.file_id}.${
src={`${getBackendUrl()}content/uploads/files/activities/${props.extension.options.activity.activity_id}/blocks/videoBlock/${blockObject.block_id}/${blockObject.block_data.file_id}.${
blockObject.block_data.file_format
}`}
></video>

View file

@ -2,10 +2,10 @@ import React, { useState } from "react";
import { ArrowLeftIcon, Cross1Icon } from "@radix-ui/react-icons";
import Modal from "../Modal";
import styled from "styled-components";
import DynamicCanvaModal from "./NewLectureModal/DynamicCanva";
import VideoModal from "./NewLectureModal/Video";
import DynamicCanvaModal from "./NewActivityModal/DynamicCanva";
import VideoModal from "./NewActivityModal/Video";
function NewLectureModal({ closeModal, submitLecture, submitFileLecture, chapterId }: any) {
function NewActivityModal({ closeModal, submitActivity, submitFileActivity, chapterId }: any) {
const [selectedView, setSelectedView] = useState("home");
return (
@ -16,29 +16,29 @@ function NewLectureModal({ closeModal, submitLecture, submitFileLecture, chapter
<button onClick={closeModal}>
<Cross1Icon />
</button>
<h1>Add New Lecture</h1>
<h1>Add New Activity</h1>
<br />
{selectedView === "home" && (
<LectureChooserWrapper>
<LectureButton onClick={() => {setSelectedView("dynamic")}}>📄</LectureButton>
<LectureButton onClick={() => {setSelectedView("video")}}>📹</LectureButton>
</LectureChooserWrapper>
<ActivityChooserWrapper>
<ActivityButton onClick={() => {setSelectedView("dynamic")}}>📄</ActivityButton>
<ActivityButton onClick={() => {setSelectedView("video")}}>📹</ActivityButton>
</ActivityChooserWrapper>
)}
{selectedView === "dynamic" && (
<DynamicCanvaModal submitLecture={submitLecture} chapterId={chapterId} />
<DynamicCanvaModal submitActivity={submitActivity} chapterId={chapterId} />
)}
{selectedView === "video" && (
<VideoModal submitFileLecture={submitFileLecture} chapterId={chapterId} />
<VideoModal submitFileActivity={submitFileActivity} chapterId={chapterId} />
)}
</Modal>
);
}
const LectureChooserWrapper = styled.div`
const ActivityChooserWrapper = styled.div`
display: flex;
flex-direction: row;
align-items: center;
@ -46,7 +46,7 @@ const LectureChooserWrapper = styled.div`
gap: 20px;
`;
const LectureButton = styled.button`
const ActivityButton = styled.button`
padding: 40px;
border-radius: 10px !important;
border: none;
@ -59,4 +59,4 @@ const LectureButton = styled.button`
}
`;
export default NewLectureModal;
export default NewActivityModal;

View file

@ -0,0 +1,36 @@
import React, { useState } from "react";
function DynamicCanvaModal({ submitActivity, chapterId }: any) {
const [activityName, setActivityName] = useState("");
const [activityDescription, setActivityDescription] = useState("");
const handleActivityNameChange = (e: any) => {
setActivityName(e.target.value);
};
const handleActivityDescriptionChange = (e: any) => {
setActivityDescription(e.target.value);
};
const handleSubmit = async (e: any) => {
e.preventDefault();
console.log({ activityName, activityDescription, chapterId });
submitActivity({
name: activityName,
chapterId: chapterId,
type: "dynamic",
});
};
return (
<div>
<div>
<input type="text" onChange={handleActivityNameChange} placeholder="Activity Name" /> <br />
<input type="text" onChange={handleActivityDescriptionChange} placeholder="Activity Description" />
<br />
<button onClick={handleSubmit}>Add Activity</button>
</div>
</div>
);
}
export default DynamicCanvaModal;

View file

@ -1,6 +1,6 @@
import React from "react";
function VideoModal({ submitFileLecture, chapterId }: any) {
function VideoModal({ submitFileActivity, chapterId }: any) {
const [video, setVideo] = React.useState(null) as any;
const [name, setName] = React.useState("");
@ -14,11 +14,11 @@ function VideoModal({ submitFileLecture, chapterId }: any) {
const handleSubmit = async (e: any) => {
e.preventDefault();
let status = await submitFileLecture(video, "video", { name, type: "video" }, chapterId);
let status = await submitFileActivity(video, "video", { name, type: "video" }, chapterId);
};
/* TODO : implement some sort of progress bar for file uploads, it is not possible yet because i'm not using axios.
and the actual upload isn't happening here anyway, it's in the submitFileLecture function */
and the actual upload isn't happening here anyway, it's in the submitFileActivity function */
return (
<div>

View file

@ -16,7 +16,7 @@ function NewChapterModal({ submitChapter , closeModal }: any) {
const handleSubmit = async (e: any) => {
e.preventDefault();
console.log({ chapterName, chapterDescription });
submitChapter({ name : chapterName, description : chapterDescription , lectures : [] });
submitChapter({ name : chapterName, description : chapterDescription , activities : [] });
};
return (

View file

@ -1,36 +0,0 @@
import React, { useState } from "react";
function DynamicCanvaModal({ submitLecture, chapterId }: any) {
const [lectureName, setLectureName] = useState("");
const [lectureDescription, setLectureDescription] = useState("");
const handleLectureNameChange = (e: any) => {
setLectureName(e.target.value);
};
const handleLectureDescriptionChange = (e: any) => {
setLectureDescription(e.target.value);
};
const handleSubmit = async (e: any) => {
e.preventDefault();
console.log({ lectureName, lectureDescription, chapterId });
submitLecture({
name: lectureName,
chapterId: chapterId,
type: "dynamic",
});
};
return (
<div>
<div>
<input type="text" onChange={handleLectureNameChange} placeholder="Lecture Name" /> <br />
<input type="text" onChange={handleLectureDescriptionChange} placeholder="Lecture Description" />
<br />
<button onClick={handleSubmit}>Add Lecture</button>
</div>
</div>
);
}
export default DynamicCanvaModal;

View file

@ -30,7 +30,7 @@ export default function middleware(req: NextRequest) {
: hostname.replace(`.localhost:3000`, "");
/* Editor route */
if (url.pathname.match(/^\/course\/[^/]+\/lecture\/[^/]+\/edit$/)) {
if (url.pathname.match(/^\/course\/[^/]+\/activity\/[^/]+\/edit$/)) {
url.pathname = `/_editor${url.pathname}`;
console.log("editor route", url.pathname);

View file

@ -1,11 +1,11 @@
import { getAPIUrl } from "@services/config/config";
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
export async function uploadNewImageFile(file: any, lecture_id: string) {
export async function uploadNewImageFile(file: any, activity_id: string) {
// Send file thumbnail as form data
const formData = new FormData();
formData.append("file_object", file);
formData.append("lecture_id", lecture_id);
formData.append("activity_id", activity_id);
return fetch(`${getAPIUrl()}blocks/image`, RequestBodyForm("POST", formData))
.then((result) => result.json())

View file

@ -1,11 +1,11 @@
import { getAPIUrl } from "@services/config/config";
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
export async function uploadNewPDFFile(file: any, lecture_id: string) {
export async function uploadNewPDFFile(file: any, activity_id: string) {
// Send file thumbnail as form data
const formData = new FormData();
formData.append("file_object", file);
formData.append("lecture_id", lecture_id);
formData.append("activity_id", activity_id);
return fetch(`${getAPIUrl()}blocks/pdf`, RequestBodyForm("POST", formData))
.then((result) => result.json())

View file

@ -2,8 +2,8 @@ import { getAPIUrl } from "@services/config/config";
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
export async function submitQuizBlock(lecture_id: string, data: any) {
const result: any = await fetch(`${getAPIUrl()}blocks/quiz/${lecture_id}"`, RequestBody("POST", data))
export async function submitQuizBlock(activity_id: string, data: any) {
const result: any = await fetch(`${getAPIUrl()}blocks/quiz/${activity_id}"`, RequestBody("POST", data))
.then((result) => result.json())
.catch((error) => console.log("error", error));
return result;

View file

@ -1,11 +1,11 @@
import { getAPIUrl } from "@services/config/config";
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
export async function uploadNewVideoFile(file: any, lecture_id: string) {
export async function uploadNewVideoFile(file: any, activity_id: string) {
// Send file thumbnail as form data
const formData = new FormData();
formData.append("file_object", file);
formData.append("lecture_id", lecture_id);
formData.append("activity_id", activity_id);
return fetch(`${getAPIUrl()}blocks/video`, RequestBodyForm("POST", formData))
.then((result) => result.json())

View file

@ -1,13 +1,13 @@
import { getAPIUrl } from "@services/config/config";
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
export async function createLecture(data: any, chapter_id: any, org_id: any) {
export async function createActivity(data: any, chapter_id: any, org_id: any) {
data.content = {};
// remove chapter_id from data
delete data.chapterId;
const result: any = await fetch(`${getAPIUrl()}lectures/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data))
const result: any = await fetch(`${getAPIUrl()}activities/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data))
.then((result) => result.json())
.catch((error) => console.log("error", error));
@ -16,17 +16,17 @@ export async function createLecture(data: any, chapter_id: any, org_id: any) {
return result;
}
export async function createFileLecture(file: File, type: string, data: any, chapter_id: any) {
export async function createFileActivity(file: File, type: string, data: any, chapter_id: any) {
// Send file thumbnail as form data
const formData = new FormData();
formData.append("coursechapter_id", chapter_id);
let endpoint = `${getAPIUrl()}lectures/video`;
let endpoint = `${getAPIUrl()}activities/video`;
if (type === "video") {
formData.append("name", data.name);
formData.append("video_file", file);
endpoint = `${getAPIUrl()}lectures/video`;
endpoint = `${getAPIUrl()}activities/video`;
}
const result: any = await fetch(endpoint, RequestBodyForm("POST", formData))
@ -38,16 +38,16 @@ export async function createFileLecture(file: File, type: string, data: any, cha
return result;
}
export async function getLecture(lecture_id: any) {
const result: any = await fetch(`${getAPIUrl()}lectures/${lecture_id}`, RequestBody("GET", null))
export async function getActivity(activity_id: any) {
const result: any = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null))
.then((result) => result.json())
.catch((error) => console.log("error", error));
return result;
}
export async function updateLecture(data: any, lecture_id: any) {
const result: any = await fetch(`${getAPIUrl()}lectures/${lecture_id}`, RequestBody("PUT", data))
export async function updateActivity(data: any, activity_id: any) {
const result: any = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("PUT", data))
.then((result) => result.json())
.catch((error) => console.log("error", error));

View file

@ -23,8 +23,8 @@ export async function closeActivity(org_id: string, activity_id: string) {
return result;
}
export async function maskLectureAsComplete(org_id: string, course_id: string, lecture_id: string) {
const result: any = await fetch(`${getAPIUrl()}activity/${org_id}/add_lecture/${course_id}/${lecture_id}`, RequestBody("POST", null))
export async function maskActivityAsComplete(org_id: string, course_id: string, activity_id: string) {
const result: any = await fetch(`${getAPIUrl()}activity/${org_id}/add_activity/${course_id}/${activity_id}`, RequestBody("POST", null))
.then((result) => result.json())
.catch((error) => console.log("error", error));
return result;