From ddc8e38277df0c56c6866bc613f60c29fbfcfb0d Mon Sep 17 00:00:00 2001 From: swve Date: Sun, 14 May 2023 15:38:43 +0200 Subject: [PATCH] wip: youtube activity --- .../course/[courseid]/edit/page.tsx | 11 +++- .../[orgslug]/(withmenu)/courses/courses.tsx | 14 ++-- .../Create/NewActivityModal/Video.tsx | 64 +++++++++++++++---- front/services/courses/activities.ts | 6 ++ front/tailwind.config.js | 1 - 5 files changed, 74 insertions(+), 22 deletions(-) diff --git a/front/app/_orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx b/front/app/_orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx index 2daca32a..22f9ef42 100644 --- a/front/app/_orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx +++ b/front/app/_orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx @@ -11,7 +11,7 @@ import { createChapter, deleteChapter, getCourseChaptersMetadata, updateChapters import { useRouter } from "next/navigation"; import NewChapterModal from "@components/Modals/Chapters/NewChapter"; import NewActivityModal from "@components/Modals/Activities/Create/NewActivity"; -import { createActivity, createFileActivity } from "@services/courses/activities"; +import { createActivity, createFileActivity, createYouTubeVideoActivity } from "@services/courses/activities"; import { getOrganizationContextInfo } from "@services/organizations/orgs"; import Modal from "@components/UI/Modal/Modal"; import { denyAccessToUser } from "@services/utils/react/middlewares/views"; @@ -89,13 +89,20 @@ function CourseEdit(params: any) { // Submit File Upload const submitFileActivity = async (file: any, type: any, activity: any, chapterId: string) => { - console.log("submitFileActivity", file); await updateChaptersMetadata(courseid, data); await createFileActivity(file, type, activity, chapterId); await getCourseChapters(); setNewActivityModal(false); }; + // Submit YouTube Video Upload + const submitVideoYouTubeActivity = async (data : any, activity: any, chapterId: string) => { + await updateChaptersMetadata(courseid, data); + await createYouTubeVideoActivity(data, activity, chapterId); + await getCourseChapters(); + setNewActivityModal(false); + }; + const deleteChapterUI = async (chapterId: any) => { console.log("deleteChapter", chapterId); await deleteChapter(chapterId); diff --git a/front/app/_orgs/[orgslug]/(withmenu)/courses/courses.tsx b/front/app/_orgs/[orgslug]/(withmenu)/courses/courses.tsx index 9d0d6269..a37f2010 100644 --- a/front/app/_orgs/[orgslug]/(withmenu)/courses/courses.tsx +++ b/front/app/_orgs/[orgslug]/(withmenu)/courses/courses.tsx @@ -16,6 +16,11 @@ interface CourseProps { courses: any; } +// function to remove "course_" from the course_id +function removeCoursePrefix(course_id: string) { + return course_id.replace("course_", ""); +} + function Courses(props: CourseProps) { const orgslug = props.orgslug; const courses = props.courses; @@ -29,10 +34,7 @@ function Courses(props: CourseProps) { setNewCourseModal(false); } - // function to remove "course_" from the course_id - function removeCoursePrefix(course_id: string) { - return course_id.replace("course_", ""); - } + return ( @@ -62,7 +64,7 @@ function Courses(props: CourseProps) { {courses.map((course: any) => (
- +
@@ -131,7 +133,7 @@ const AdminEditsArea = (props: any) => { - + diff --git a/front/components/Modals/Activities/Create/NewActivityModal/Video.tsx b/front/components/Modals/Activities/Create/NewActivityModal/Video.tsx index 36d00097..d0513edf 100644 --- a/front/components/Modals/Activities/Create/NewActivityModal/Video.tsx +++ b/front/components/Modals/Activities/Create/NewActivityModal/Video.tsx @@ -2,11 +2,14 @@ import FormLayout, { ButtonBlack, Flex, FormField, FormLabel, FormMessage, Input import React, { useState } from "react"; import * as Form from '@radix-ui/react-form'; import BarLoader from "react-spinners/BarLoader"; +import { Youtube } from "lucide-react"; function VideoModal({ submitFileActivity, chapterId }: any) { const [video, setVideo] = React.useState(null) as any; const [isSubmitting, setIsSubmitting] = useState(false); const [name, setName] = React.useState(""); + const [youtubeUrl, setYoutubeUrl] = React.useState(""); + const [selectedView, setSelectedView] = React.useState("file") as any; const handleVideoChange = (event: React.ChangeEvent) => { setVideo(event.target.files[0]); @@ -16,18 +19,29 @@ function VideoModal({ submitFileActivity, chapterId }: any) { setName(event.target.value); }; + const handleYoutubeUrlChange = (event: React.ChangeEvent) => { + setYoutubeUrl(event.target.value); + }; + const handleSubmit = async (e: any) => { e.preventDefault(); setIsSubmitting(true); - let status = await submitFileActivity(video, "video", { name, type: "video" }, chapterId); + if (selectedView === "file") { + let status = await submitFileActivity(video, "video", { name, type: "video" }, chapterId); setIsSubmitting(false); + } + if (selectedView === "youtube") { + let status = await submitFileActivity(video, "video", { name, type: "video" }, chapterId); + setIsSubmitting(false); + } + }; /* 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 submitFileActivity function */ return ( - + Video name @@ -37,20 +51,44 @@ function VideoModal({ submitFileActivity, chapterId }: any) { - - - Video file - Please provide a video for your activity - - - - - +
+
+
+
{ setSelectedView("file") }} className="rounded-full bg-slate-900 text-zinc-50 py-2 px-4 text-sm drop-shadow-md hover:cursor-pointer hover:bg-slate-700 ">Video upload
+
{ setSelectedView("youtube") }} className="rounded-full bg-slate-900 text-zinc-50 py-2 px-4 text-sm drop-shadow-md hover:cursor-pointer hover:bg-slate-700">YouTube Video
+
+ {selectedView === "file" && (
+ + + Video file + Please provide a video for your activity + + + + + +
)} + {selectedView === "youtube" && ( + +
+ + + YouTube URL + Please provide a video for your activity + + + + + +
+ )} +
+
- - {isSubmitting ? : "Create activity"} + + {isSubmitting ? : "Create activity"} diff --git a/front/services/courses/activities.ts b/front/services/courses/activities.ts index 209b5325..49b41246 100644 --- a/front/services/courses/activities.ts +++ b/front/services/courses/activities.ts @@ -36,6 +36,12 @@ export async function createFileActivity(file: File, type: string, data: any, ch return res; } +export async function createYouTubeVideoActivity(data: any, activity: any, chapter_id: any) { + const result = await fetch(`${getAPIUrl()}activities/youtubevideo?coursechapter_id=${chapter_id}`, RequestBody("POST", data)); + const res = await result.json(); + return res; +} + export async function getActivity(activity_id: any) { const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null)); const res = await result.json(); diff --git a/front/tailwind.config.js b/front/tailwind.config.js index fcec4f79..122847cf 100644 --- a/front/tailwind.config.js +++ b/front/tailwind.config.js @@ -3,7 +3,6 @@ module.exports = { content: [ './app/**/*.{js,jsx,ts,tsx}', './components/**/*.{js,jsx,ts,tsx}', - ], theme: { extend: {},