diff --git a/components.json b/components.json index fdc0103..0e55aa8 100644 --- a/components.json +++ b/components.json @@ -1,16 +1,16 @@ { "$schema": "https://ui.shadcn.com/schema.json", "style": "default", - "rsc": false, + "rsc": true, "tsx": true, "tailwind": { "config": "tailwind.config.js", - "css": "app/globals.css", + "css": "styles/globals.css", "baseColor": "slate", - "cssVariables": false + "cssVariables": true }, "aliases": { "components": "@/components", "utils": "@/lib/utils" } -} \ No newline at end of file +} diff --git a/components/AddCourseDialog.tsx b/components/AddCourseDialog.tsx new file mode 100644 index 0000000..32f424c --- /dev/null +++ b/components/AddCourseDialog.tsx @@ -0,0 +1,107 @@ +"use client"; + +import * as z from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; + +import { Button } from "@/components/ui/button"; +import { + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogClose, + DialogTitle, +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; + +const formSchema = z.object({ + courseName: z.string().min(2), + ListTAs: z.string().min(2), +}); + +export function AddCourseDialog() { + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + courseName: "", + ListTAs: "", + }, + }); + + async function onSubmit(values: z.infer) { + let courseName = values.courseName; + // make API call to create course by api at /api/courses/[courseName]/create + let response = await fetch( + "http://localhost:3000/api/" + courseName + "/create", + { + method: "GET", + } + ); + + response = await response; + + if (response.status == 200) { + console.log("Course created"); + } else { + console.log("Course not created"); + } + } + + return ( + + + Create new course + + Add course details and save when you're done. + + +
+ + ( + + Course Name + + + + + + )} + /> + ( + + List TAs + + + + Enter as comma-seperated list + + + )} + /> + + + + + + + +
+ ); +} diff --git a/components/Navbar.tsx b/components/Navbar.tsx new file mode 100644 index 0000000..d529b85 --- /dev/null +++ b/components/Navbar.tsx @@ -0,0 +1,67 @@ +"use client"; +import Link from "next/link"; +import { FC } from "react"; +import { useCourseContext } from "../context/courseContext"; +import { Course, CourseList, User } from "@/lib/types"; + +import { UserNav } from "./user-nav"; +import { useRouter } from "next/router"; + +type NavbarProps = { + courseList: CourseList; + // user: User; +}; + +const Navbar: FC = ({ courseList }) => { + const { currentCourse, setCurrentCourse } = useCourseContext(); + + const pathName = useRouter(); + + const isActive = (route: string) => { + const pathList = pathName.asPath.split("/"); + /*pathList = ["", dashboard] or ["", courses, [courseName], ...]*/ + return route === pathList[1]; + }; + return ( + + ); +}; + +export default Navbar; diff --git a/components/QuizEditor.tsx b/components/QuizEditor.tsx new file mode 100644 index 0000000..5edf94e --- /dev/null +++ b/components/QuizEditor.tsx @@ -0,0 +1,182 @@ +"use client"; + +import { Label } from "@/components/ui/label"; +import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; +import { Textarea } from "@/components/ui/textarea"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; + +import { ScrollArea } from "@/components/ui/scroll-area"; + +import { Dispatch, SetStateAction, useState } from "react"; +import { Quiz, QuizQuestion } from "@/lib/types"; + +interface quizQuestionsProps { + questions: QuizQuestion[]; + setQuestions: Dispatch>; +} + +const QuizEditor: React.FC = ({ + questions, + setQuestions, +}) => { + // const [questions, setQuestions] = useState(questions); + + const defaultMCQQuestion: QuizQuestion = { + questionNum: questions.length + 1, + questionType: "MCQ", + question: "", + options: ["", "", "", ""], // Assuming a default of 4 options + answer: 1, // Assuming no answer selected by default + points: 10, // Default points value + }; + + const defaultFRQQuestion: QuizQuestion = { + questionNum: questions.length + 1, + questionType: "FRQ", + question: "", + options: [], + answer: "", + points: 80, // Default points value for FRQ + }; + + // Function to add a new MCQ question + const addMCQQuestion = () => { + setQuestions( + questions.concat({ + ...defaultMCQQuestion, + questionNum: questions.length + 1, + }) + ); + }; + + // Function to add a new FRQ question + const addFRQQuestion = () => { + setQuestions( + questions.concat({ + ...defaultFRQQuestion, + questionNum: questions.length + 1, + }) + ); + }; + + const deleteQuestion = (questionNum: number) => { + setQuestions(questions.filter((q) => q.questionNum !== questionNum)); + }; + + // Function to handle reordering the question numbers after deletion + const reorderQuestions = (questions: QuizQuestion[]) => { + return questions.map((q, index) => ({ + ...q, + questionNum: index + 1, // Reset question numbers to be in order + })); + }; + + // Adjusted delete function that also reorders question numbers after deletion + const handleDeleteQuestion = (questionNum: number) => { + const updatedQuestions = questions.filter( + (q) => q.questionNum !== questionNum + ); + setQuestions(reorderQuestions(updatedQuestions)); + }; + + const handleQuestionChange = (index: number, newText: string) => { + const updatedQuestions = [...questions]; + updatedQuestions[index].question = newText; + setQuestions(updatedQuestions); + }; + + const handleOptionChange = ( + questionIndex: number, + optionIndex: number, + newOptionText: string + ) => { + const updatedQuestions = [...questions]; + updatedQuestions[questionIndex].options[optionIndex] = newOptionText; + setQuestions(updatedQuestions); + }; + + const addOption = (questionIndex: number) => { + const updatedQuestions = [...questions]; + updatedQuestions[questionIndex].options.push(""); + setQuestions(updatedQuestions); + }; + + const deleteOption = (questionIndex: number, optionIndex: number) => { + const updatedQuestions = [...questions]; + updatedQuestions[questionIndex].options.splice(optionIndex, 1); + setQuestions(updatedQuestions); + }; + + const handleSubmit = () => { + /* + 1. Need a popup to make sure the Ta finished editing. + 2. update the quesitons + 3. back to the previous page + */ + }; + + return ( +
+ +
+ {questions.map((q, qIndex) => ( +
+ {q.questionNum}. + handleQuestionChange(qIndex, e.target.value)} + placeholder="Type your question here." + /> + {q.questionType == "MCQ" && ( + <> + {q.options.map((option, oIndex) => ( +
+ + handleOptionChange(qIndex, oIndex, e.target.value) + } + /> + +
+ ))} +
+ +
+ + )} + +
+ ))} +
+ + +
+ +
+ ); +}; + +export default QuizEditor; diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx new file mode 100644 index 0000000..d7bbc88 --- /dev/null +++ b/components/Sidebar.tsx @@ -0,0 +1,66 @@ +"use client"; +import Link from "next/link"; +import { FC, useEffect, useState } from "react"; +import { useCourseContext } from "../context/courseContext"; +import { useRouter } from "next/router"; + +const Sidebar: FC = () => { + const { currentCourse, setCurrentCourse } = useCourseContext(); + const [tabList, setTableList] = useState([ + "Home", + "Assignments", + "Quizzes", + "Modules", + "Files", + ]); + const router = useRouter(); + + const isActive = (it: string) => { + // If the item is 'Home', check against the base path ('/') + const paramList = router.asPath.split("/"); + if (it === "Home") { + return paramList.length === 2; + } + // Otherwise, compare against the lowercased item + return paramList[2] === it.toLocaleLowerCase(); + }; + useEffect(() => { + // If currentCourse is not set, redirect to the home page + if (!currentCourse) { + router.push("/"); + } + }, [currentCourse, router]); + + if (!currentCourse) { + return
Loading...
; + } + + return ( + + ); +}; + +export default Sidebar; diff --git a/components/ui/avatar.tsx b/components/ui/avatar.tsx new file mode 100644 index 0000000..51e507b --- /dev/null +++ b/components/ui/avatar.tsx @@ -0,0 +1,50 @@ +"use client" + +import * as React from "react" +import * as AvatarPrimitive from "@radix-ui/react-avatar" + +import { cn } from "@/lib/utils" + +const Avatar = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +Avatar.displayName = AvatarPrimitive.Root.displayName + +const AvatarImage = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AvatarImage.displayName = AvatarPrimitive.Image.displayName + +const AvatarFallback = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName + +export { Avatar, AvatarImage, AvatarFallback } diff --git a/components/ui/button.tsx b/components/ui/button.tsx new file mode 100644 index 0000000..0ba4277 --- /dev/null +++ b/components/ui/button.tsx @@ -0,0 +1,56 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const buttonVariants = cva( + "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + { + variants: { + variant: { + default: "bg-primary text-primary-foreground hover:bg-primary/90", + destructive: + "bg-destructive text-destructive-foreground hover:bg-destructive/90", + outline: + "border border-input bg-background hover:bg-accent hover:text-accent-foreground", + secondary: + "bg-secondary text-secondary-foreground hover:bg-secondary/80", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-10 px-4 py-2", + sm: "h-9 rounded-md px-3", + lg: "h-11 rounded-md px-8", + icon: "h-10 w-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +export interface ButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + asChild?: boolean +} + +const Button = React.forwardRef( + ({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : "button" + return ( + + ) + } +) +Button.displayName = "Button" + +export { Button, buttonVariants } diff --git a/components/ui/dialog.tsx b/components/ui/dialog.tsx new file mode 100644 index 0000000..cad6f58 --- /dev/null +++ b/components/ui/dialog.tsx @@ -0,0 +1,122 @@ +"use client" + +import * as React from "react" +import * as DialogPrimitive from "@radix-ui/react-dialog" +import { X } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Dialog = DialogPrimitive.Root + +const DialogTrigger = DialogPrimitive.Trigger + +const DialogPortal = DialogPrimitive.Portal + +const DialogClose = DialogPrimitive.Close + +const DialogOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogOverlay.displayName = DialogPrimitive.Overlay.displayName + +const DialogContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + {children} + + + Close + + + +)) +DialogContent.displayName = DialogPrimitive.Content.displayName + +const DialogHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +DialogHeader.displayName = "DialogHeader" + +const DialogFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +DialogFooter.displayName = "DialogFooter" + +const DialogTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogTitle.displayName = DialogPrimitive.Title.displayName + +const DialogDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogDescription.displayName = DialogPrimitive.Description.displayName + +export { + Dialog, + DialogPortal, + DialogOverlay, + DialogClose, + DialogTrigger, + DialogContent, + DialogHeader, + DialogFooter, + DialogTitle, + DialogDescription, +} diff --git a/components/ui/dropdown-menu.tsx b/components/ui/dropdown-menu.tsx new file mode 100644 index 0000000..f69a0d6 --- /dev/null +++ b/components/ui/dropdown-menu.tsx @@ -0,0 +1,200 @@ +"use client" + +import * as React from "react" +import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu" +import { Check, ChevronRight, Circle } from "lucide-react" + +import { cn } from "@/lib/utils" + +const DropdownMenu = DropdownMenuPrimitive.Root + +const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger + +const DropdownMenuGroup = DropdownMenuPrimitive.Group + +const DropdownMenuPortal = DropdownMenuPrimitive.Portal + +const DropdownMenuSub = DropdownMenuPrimitive.Sub + +const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup + +const DropdownMenuSubTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & { + inset?: boolean + } +>(({ className, inset, children, ...props }, ref) => ( + + {children} + + +)) +DropdownMenuSubTrigger.displayName = + DropdownMenuPrimitive.SubTrigger.displayName + +const DropdownMenuSubContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DropdownMenuSubContent.displayName = + DropdownMenuPrimitive.SubContent.displayName + +const DropdownMenuContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, sideOffset = 4, ...props }, ref) => ( + + + +)) +DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName + +const DropdownMenuItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & { + inset?: boolean + } +>(({ className, inset, ...props }, ref) => ( + +)) +DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName + +const DropdownMenuCheckboxItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, checked, ...props }, ref) => ( + + + + + + + {children} + +)) +DropdownMenuCheckboxItem.displayName = + DropdownMenuPrimitive.CheckboxItem.displayName + +const DropdownMenuRadioItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + + + + {children} + +)) +DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName + +const DropdownMenuLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & { + inset?: boolean + } +>(({ className, inset, ...props }, ref) => ( + +)) +DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName + +const DropdownMenuSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName + +const DropdownMenuShortcut = ({ + className, + ...props +}: React.HTMLAttributes) => { + return ( + + ) +} +DropdownMenuShortcut.displayName = "DropdownMenuShortcut" + +export { + DropdownMenu, + DropdownMenuTrigger, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuCheckboxItem, + DropdownMenuRadioItem, + DropdownMenuLabel, + DropdownMenuSeparator, + DropdownMenuShortcut, + DropdownMenuGroup, + DropdownMenuPortal, + DropdownMenuSub, + DropdownMenuSubContent, + DropdownMenuSubTrigger, + DropdownMenuRadioGroup, +} diff --git a/components/ui/form.tsx b/components/ui/form.tsx new file mode 100644 index 0000000..4603f8b --- /dev/null +++ b/components/ui/form.tsx @@ -0,0 +1,176 @@ +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" +import { Slot } from "@radix-ui/react-slot" +import { + Controller, + ControllerProps, + FieldPath, + FieldValues, + FormProvider, + useFormContext, +} from "react-hook-form" + +import { cn } from "@/lib/utils" +import { Label } from "@/components/ui/label" + +const Form = FormProvider + +type FormFieldContextValue< + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath +> = { + name: TName +} + +const FormFieldContext = React.createContext( + {} as FormFieldContextValue +) + +const FormField = < + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath +>({ + ...props +}: ControllerProps) => { + return ( + + + + ) +} + +const useFormField = () => { + const fieldContext = React.useContext(FormFieldContext) + const itemContext = React.useContext(FormItemContext) + const { getFieldState, formState } = useFormContext() + + const fieldState = getFieldState(fieldContext.name, formState) + + if (!fieldContext) { + throw new Error("useFormField should be used within ") + } + + const { id } = itemContext + + return { + id, + name: fieldContext.name, + formItemId: `${id}-form-item`, + formDescriptionId: `${id}-form-item-description`, + formMessageId: `${id}-form-item-message`, + ...fieldState, + } +} + +type FormItemContextValue = { + id: string +} + +const FormItemContext = React.createContext( + {} as FormItemContextValue +) + +const FormItem = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => { + const id = React.useId() + + return ( + +
+ + ) +}) +FormItem.displayName = "FormItem" + +const FormLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + const { error, formItemId } = useFormField() + + return ( +