-
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
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IComment[], string> = (...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 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
frontend/src/app/courses/[courseCode]/exams/[examId]/[questionId]/page.tsx
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,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 ( | ||
<main> | ||
{isLoading && <p>Loading...</p>} | ||
{!isError && !isLoading && comments?.map(comment => ( | ||
<> | ||
<hr /> | ||
<Comment comment={comment} /> | ||
</> | ||
)) | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Comment as IComment } from '@/types'; | ||
|
||
export default function Comment({ comment }: { comment: IComment }) { | ||
return ( | ||
<div className="ml-5 block max-w-sm p-1 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700" > | ||
<h1 className="p-2">(id: {comment.commentId}) | {comment.commentText}</h1> | ||
<p className="pl-8 p-2 ">reply</p> | ||
{comment.children?.map((c) => <Comment key={c.commentId} comment={c} />)} | ||
</div> | ||
) | ||
} |
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