Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 61 add question preview modal component #63

Merged
merged 8 commits into from
Jan 24, 2025
Merged
78 changes: 51 additions & 27 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
"check-all": "npm run lint && npm run format:check && npm run typecheck"
},
"dependencies": {
"@radix-ui/react-collapsible": "^1.1.2",
"@hookform/resolvers": "^3.9.1",
"@radix-ui/react-collapsible": "^1.1.2",
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-separator": "^1.1.1",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.6",
"@radix-ui/react-visually-hidden": "^1.1.1",
"@tanstack/react-query": "^5.51.23",
"@tanstack/react-query-devtools": "^5.51.23",
"@types/js-cookie": "^3.0.6",
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/ui/Question/data-grid.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the naming convention shall be lower case iirc (Question -> question)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the naming convention shall be lower case iirc (Question -> question)

Hi Yunho. I follow the style-guide.md. It says the folder name in /Components should use PascalCase.
Screenshot 2025-01-15 at 4 53 14 pm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, hh, my fault!

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import { DatagridProps, Question } from "@/types/question";

/**
* The Datagrid component is a flexible, paginated data table with sorting and navigation features.
Expand Down Expand Up @@ -167,7 +168,7 @@ export function Datagrid({
<Pagination
totalPages={totalPages}
currentPage={currentPage}
onPageChange={(page) => handlePageChange(page)}
onPageChange={(page: number) => handlePageChange(page)}
className="mr-20 mt-5 flex justify-end"
/>
</div>
Expand Down
76 changes: 76 additions & 0 deletions client/src/components/ui/Question/preview-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import "katex/dist/katex.min.css";

import * as VisuallyHidden from "@radix-ui/react-visually-hidden";
import { useEffect, useState } from "react";
import Latex from "react-latex-next";

import {
Dialog,
DialogContent,
DialogDescription,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { PreviewModalProps } from "@/types/question";

import { Button } from "../button";

export default function PreviewModal({
children,
dataContext,
}: PreviewModalProps) {
const [question, setQuestion] = useState<string>(dataContext.question);

useEffect(() => {
if (dataContext?.question) {
setQuestion(dataContext.question);
}
}, [dataContext]);
return (
<>
<Dialog>
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent
className="flex h-auto w-[95%] max-w-[750px] flex-col items-center rounded-[40px] border-0 bg-accent p-1 shadow-lg"
style={{ borderRadius: "32px" }}
>
<VisuallyHidden.Root>
<DialogTitle>Preview Data</DialogTitle>
<DialogDescription></DialogDescription>
</VisuallyHidden.Root>

<div className="flex h-full w-full flex-col space-y-4 rounded-[30px] bg-white px-10 py-4 text-xl">
{/* Question */}
<div className="flex-grow space-y-4">
<div className="flex space-x-4 text-2xl font-semibold text-gray-600">
<span>{dataContext.questionName}</span>
<span>[{dataContext.mark} marks]</span>
</div>
<Latex>{question}</Latex>
</div>
{/* Solution */}
<div>
<p className="text-2xl font-semibold text-gray-600">Solution</p>
<div>
<p>
Answer:{" "}
<span className="font-bold">{dataContext.answer}</span>
</p>
<p>{dataContext.solution}</p>
</div>
</div>

{/* Close Button */}
<div className="mt-auto flex justify-center">
<DialogTrigger asChild>
<Button variant={"ghost"} className="w-36 border border-black">
Close
</Button>
</DialogTrigger>
</div>
</div>
</DialogContent>
</Dialog>
</>
);
}
2 changes: 2 additions & 0 deletions client/src/components/ui/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PaginationProps } from "@/types/question";

export function Pagination({
totalPages,
currentPage,
Expand Down
2 changes: 2 additions & 0 deletions client/src/pages/api/question/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import { NextApiRequest, NextApiResponse } from "next";

import { Question } from "@/types/question";

// Mock data representing question entries
const mockQuestions: Question[] = [
{
Expand Down
Loading
Loading