diff --git a/frontend/src/api/useComments.ts b/frontend/src/api/useComments.ts new file mode 100644 index 0000000..73a0960 --- /dev/null +++ b/frontend/src/api/useComments.ts @@ -0,0 +1,17 @@ +'use client' +import useSWR, { Fetcher } from 'swr'; +import { Comment as IComment }from '@/types'; + +const ENDPOINT = `${process.env.API_URL}/api/questions/`; + +const fetcher: Fetcher = (...args) => fetch(...args).then(res => res.json()) + +export default function useComments(questionId: number) { + const { data, error, isLoading } = useSWR(ENDPOINT + questionId +'/comments', fetcher) + + return { + comments: data, + isLoading, + isError: error + } +} \ No newline at end of file diff --git a/frontend/src/app/courses/[courseCode]/course-profile/page.tsx b/frontend/src/app/courses/[courseCode]/course-profile/page.tsx index f905087..c106e92 100644 --- a/frontend/src/app/courses/[courseCode]/course-profile/page.tsx +++ b/frontend/src/app/courses/[courseCode]/course-profile/page.tsx @@ -9,11 +9,11 @@ export default function CourseProfile({ params }: { params: { courseCode: string
{isLoading &&

Loading...

} {!isError && !isLoading && ( -
- -

{course!.coursecode} | {course!.coursename}

+
+ +

{course!.courseCode} | {course!.courseName}

-

{course!.coursedescription}

+

{course!.courseDescription}

)}
diff --git a/frontend/src/app/courses/[courseCode]/exams/[examId]/[questionId]/page.tsx b/frontend/src/app/courses/[courseCode]/exams/[examId]/[questionId]/page.tsx new file mode 100644 index 0000000..884af66 --- /dev/null +++ b/frontend/src/app/courses/[courseCode]/exams/[examId]/[questionId]/page.tsx @@ -0,0 +1,20 @@ +'use client'; +import useComments from '@/api/useComments'; +import Comment from '@/components/Comment'; + +export default function Question({ params }: { params: { courseCode: string, examId: number, questionId: number }}) { + const { comments, isLoading, isError } = useComments(params.questionId); + + return ( +
+ {isLoading &&

Loading...

} + {!isError && !isLoading && comments?.map(comment => ( + <> +
+ + + )) + } +
+ ); +} \ No newline at end of file diff --git a/frontend/src/app/courses/[courseCode]/exams/[examId]/page.tsx b/frontend/src/app/courses/[courseCode]/exams/[examId]/page.tsx index dc69cbc..7ae0531 100644 --- a/frontend/src/app/courses/[courseCode]/exams/[examId]/page.tsx +++ b/frontend/src/app/courses/[courseCode]/exams/[examId]/page.tsx @@ -9,17 +9,17 @@ export default function Exam({ params }: { params: { courseCode: string, examId: return (
-

{`${params.courseCode} ${exam?.examtype}`}

-

{`${exam?.examyear} Semester ${exam?.examsemester}`}

+

{`${params.courseCode} ${exam?.examType}`}

+

{`${exam?.examYear} Semester ${exam?.examSemester}`}

{isLoadingQuestions &&

Loading...

} {!isErrorQuestions && !isLoadingQuestions && questions?.map(question => ( <>
-
- -

{question.questiontype}

+
+ +

{question.questionType}

-

{question.questiontext}

+

{question.questionText}

)) diff --git a/frontend/src/app/courses/[courseCode]/exams/page.tsx b/frontend/src/app/courses/[courseCode]/exams/page.tsx index eb7f036..4dc5fcb 100644 --- a/frontend/src/app/courses/[courseCode]/exams/page.tsx +++ b/frontend/src/app/courses/[courseCode]/exams/page.tsx @@ -15,9 +15,9 @@ export default function Exams({ params }: { params: { courseCode: string }}) {
-

{exam.examyear} | S{exam.examsemester}

+

{exam.examYear} | S{exam.examSemester}

-

{exam.examtype}

+

{exam.examType}

)) diff --git a/frontend/src/app/courses/[courseCode]/notes/page.tsx b/frontend/src/app/courses/[courseCode]/notes/page.tsx index 9ee11e7..dd48b17 100644 --- a/frontend/src/app/courses/[courseCode]/notes/page.tsx +++ b/frontend/src/app/courses/[courseCode]/notes/page.tsx @@ -5,15 +5,15 @@ export default function Notes({ params }: { params: { courseCode: string }}) { const course: Course = useMemo(() => { // query backend here return { - coursecode: params.courseCode.toUpperCase(), - coursename: 'Course Name', - coursedescription: 'Some sort of description' + courseCode: params.courseCode.toUpperCase(), + courseName: 'Course Name', + courseDescription: 'Some sort of description' } }, [params.courseCode]) return (
-

Study material for {course.coursecode}

+

Study material for {course.courseCode}

There will be some cards here
); diff --git a/frontend/src/app/courses/page.tsx b/frontend/src/app/courses/page.tsx index 4449176..4de6f20 100644 --- a/frontend/src/app/courses/page.tsx +++ b/frontend/src/app/courses/page.tsx @@ -10,11 +10,11 @@ export default function Courses() { {!isError && !isLoading && courses?.map(course => ( <>
-
- -

{course.coursecode} | {course.coursename}

+
+ +

{course.courseCode} | {course.courseName}

-

{course.coursedescription}

+

{course.courseDescription}

)) diff --git a/frontend/src/components/Comment.tsx b/frontend/src/components/Comment.tsx new file mode 100644 index 0000000..64a9794 --- /dev/null +++ b/frontend/src/components/Comment.tsx @@ -0,0 +1,11 @@ +import { Comment as IComment } from '@/types'; + +export default function Comment({ comment }: { comment: IComment }) { + return ( +
+

(id: {comment.commentId}) | {comment.commentText}

+

reply

+ {comment.children?.map((c) => )} +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/Navigation.tsx b/frontend/src/components/Navigation.tsx index 9767f64..98a50ce 100644 --- a/frontend/src/components/Navigation.tsx +++ b/frontend/src/components/Navigation.tsx @@ -247,7 +247,7 @@ export function Navigation(props: React.ComponentPropsWithoutRef<'nav'>) { { title: `Exams`, links: (!isLoading && !isError && !!exams) ? exams?.map((exam) => ({ - title: `${exam.examyear} S${exam.examsemester}`, + title: `${exam.examYear} S${exam.examSemester}`, href: `/courses/${courseCode}/exams/${exam.examId}`, })) : [] }, diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 2b52ff6..69d101e 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -1,19 +1,33 @@ export type Course = { - coursecode: string - coursename: string - coursedescription: string + courseCode: string + courseName: string + courseDescription: string } export type Exam = { examId: number - examyear: number - examsemester: number - examtype: string + examYear: number + examSemester: number + examType: string } export type Question = { - questionid: number - questiontext: string - questiontype: string - questionpng: string + questionId: number + questionText: string + questionType: string + questionPng: string +} + +export type Comment = { + commentId: number + parentCommentId: number | null + commentText: string + commentPNG: string | null + isCorrect: boolean + isEndorsed: boolean + upvotes: number + downvotes: number + created_at: string + updated_at: string + children?: Comment[] } \ No newline at end of file