diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0ead04f..472a96a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -80,6 +80,7 @@ model Course { updatedAt DateTime @updatedAt } +// Additional resources model Resource { id String @id // Client generates UUID userId String @@ -93,6 +94,7 @@ model Resource { updatedAt DateTime @updatedAt } +// Additional resources model Draft { id String @id @default(uuid()) userId String diff --git a/src/components/content/SelectedContentItem.js b/src/components/content/SelectedContentItem.js index 3f737da..72888ec 100644 --- a/src/components/content/SelectedContentItem.js +++ b/src/components/content/SelectedContentItem.js @@ -2,12 +2,22 @@ import React from "react"; import Image from "next/image"; import { useImageProxy } from "@/hooks/useImageProxy"; import { formatUnixTimestamp } from "@/utils/time"; +import { Button } from 'primereact/button'; -const SelectedContentItem = ({ content }) => { +const SelectedContentItem = ({ content, onRemove }) => { const { returnImageProxy } = useImageProxy(); return ( -
+
+
{processedEvent && ( diff --git a/src/components/content/courses/DraftCourseLesson.js b/src/components/content/courses/DraftCourseLesson.js index 86c1dd5..92fa509 100644 --- a/src/components/content/courses/DraftCourseLesson.js +++ b/src/components/content/courses/DraftCourseLesson.js @@ -3,6 +3,7 @@ import { Tag } from "primereact/tag"; import { Message } from "primereact/message"; import Image from "next/image"; import { useImageProxy } from "@/hooks/useImageProxy"; +import { formatDateTime, formatUnixTimestamp } from "@/utils/time"; import dynamic from "next/dynamic"; const MDDisplay = dynamic( @@ -17,6 +18,7 @@ const DraftCourseLesson = ({ lesson, course }) => { const [isPublished, setIsPublished] = useState(false); useEffect(() => { if (lesson?.kind) { + console.log(lesson); setIsPublished(true); } else { setIsPublished(false); @@ -52,6 +54,13 @@ const DraftCourseLesson = ({ lesson, course }) => {

+ { + lesson?.createdAt ? ( +

{formatDateTime(lesson?.createdAt)}

+ ) : ( +

{formatUnixTimestamp(lesson?.published_at)}

+ ) + }
{isPublished ? ( diff --git a/src/components/forms/course/LessonSelector.js b/src/components/forms/course/LessonSelector.js index d8eaa66..b53c80d 100644 --- a/src/components/forms/course/LessonSelector.js +++ b/src/components/forms/course/LessonSelector.js @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import { Dropdown } from 'primereact/dropdown'; import { Button } from 'primereact/button'; import { Dialog } from 'primereact/dialog'; +import { Accordion, AccordionTab } from 'primereact/accordion'; import ResourceForm from '../ResourceForm'; import WorkshopForm from '../WorkshopForm'; import ContentDropdownItem from '@/components/content/dropdowns/ContentDropdownItem'; @@ -82,18 +83,31 @@ const LessonSelector = ({ isPaidCourse, lessons, setLessons, allContent }) => { console.log("contentOptions", contentOptions); }, [contentOptions]); - const handleContentSelect = (selectedContent) => { - if (selectedContent && !lessons.some(lesson => lesson.id === selectedContent.id)) { - setLessons([...lessons, { ...selectedContent, index: lessons.length }]); + const handleContentSelect = (selectedContent, index) => { + if (selectedContent) { + const updatedLessons = [...lessons]; + updatedLessons[index] = { ...selectedContent, index }; + setLessons(updatedLessons); } }; + const handleRemoveContent = (index) => { + const updatedLessons = [...lessons]; + updatedLessons[index] = { index }; // Reset the lesson to an empty state + setLessons(updatedLessons); + }; + const removeLesson = (index) => { const updatedLessons = lessons.filter((_, i) => i !== index) .map((lesson, newIndex) => ({ ...lesson, index: newIndex })); setLessons(updatedLessons); }; + const addNewLesson = (e) => { + e.preventDefault(); // Prevent form submission + setLessons([...lessons, { index: lessons.length }]); + }; + const handleNewResourceSave = (newResource) => { setLessons([...lessons, { ...newResource, index: lessons.length }]); setShowResourceForm(false); @@ -104,35 +118,58 @@ const LessonSelector = ({ isPaidCourse, lessons, setLessons, allContent }) => { setShowWorkshopForm(false); }; + const AccordianHeader = ({lesson, index}) => { + return ( +
+

Lesson {index + 1}

+
+ ); + }; + return (

Lessons

- {lessons.map((lesson, index) => ( -
- -
- ))} -
- handleContentSelect(e.value)} - placeholder="Select Existing Lesson" - optionLabel="label" - optionGroupLabel="label" - optionGroupChildren="items" - itemTemplate={(option) => } - value={null} - /> -
-
-
+ + {lessons.map((lesson, index) => ( + }> +
+ handleContentSelect(e.value, index)} + placeholder="Select Existing Lesson" + optionLabel="label" + optionGroupLabel="label" + optionGroupChildren="items" + itemTemplate={(option) => handleContentSelect(content, index)} />} + value={lesson.id ? lesson : null} + /> +
+
+ {lesson.id ? null : ( + <> +
+ {lesson.id && ( +
+ handleRemoveContent(index)} + /> +
+ )} +
+ ))} +
+