-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use client' | ||
import useSWR, { Fetcher } from 'swr'; | ||
import { Exam } from '@/types'; | ||
|
||
const ENDPOINT = `${process.env.API_URL}/api/courses/`; | ||
|
||
const fetcher: Fetcher<Exam[], string> = (...args) => fetch(...args).then(res => res.json()) | ||
|
||
export default function useExams(courseCode: string) { | ||
const { data, error, isLoading } = useSWR(ENDPOINT + courseCode + '/exams', fetcher) | ||
|
||
return { | ||
exams: data, | ||
isLoading, | ||
isError: error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import { useMemo } from 'react'; | ||
import { Course } from '@/types'; | ||
'use client' | ||
import useExams from '@/api/useExams'; | ||
import Link from 'next/link'; | ||
|
||
export default function Exams({ params }: { params: { courseCode: string }}) { | ||
const course: Course = useMemo(() => { | ||
// query backend here | ||
return { | ||
coursecode: params.courseCode.toUpperCase(), | ||
coursename: 'Course Name', | ||
coursedescription: 'Some sort of description' | ||
} | ||
}, [params.courseCode]) | ||
const { exams, isLoading, isError } = useExams(params.courseCode); | ||
|
||
return ( | ||
<main> | ||
<h1>Exams for {course.coursecode}</h1> | ||
<h1>Exams for {params.courseCode}</h1> | ||
There will be some cards here | ||
{isLoading && <p>Loading...</p>} | ||
{!isError && !isLoading && exams?.map(exam => ( | ||
<> | ||
<hr /> | ||
<div key={exam.examid}> | ||
<Link href={`/courses/${params.courseCode}/exams/${exam.examid}`}> | ||
<h2>{exam.examyear} | S{exam.examsemester}</h2> | ||
</Link> | ||
<p>{exam.examtype}</p> | ||
</div> | ||
</> | ||
)) | ||
} | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters