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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,6 +8,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import { DatagridProps, Question } from "@/types/question";

import { Button } from "../button";
import { Pagination } from "../pagination";
Expand Down Expand Up @@ -168,7 +169,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
100 changes: 100 additions & 0 deletions client/src/components/ui/Question/preview-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as VisuallyHidden from "@radix-ui/react-visually-hidden";
import { useEffect, useState } from "react";

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

import { Button } from "../button";
import { MathInput } from "../math-input";

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

const handleSolutionVisible = () => {
setIsSolutionVisible(!isSolutionVisible);
};

// When close button is clicked, bring the modified question data back to Create page
const handleDialogClose = () => {
onClose(question);
};

useEffect(() => {
if (dataContext?.question) {
setQuestion(dataContext.question);
}
}, [dataContext]);
return (
<>
<Dialog>
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent
className="flex h-full max-h-[750px] w-[95%] max-w-[750px] 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="h-full w-full space-y-6 overflow-y-auto rounded-[30px] border-accent bg-white px-10 py-4 text-xl">
{/* Question */}
<div className="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>
<p></p>
<MathInput
input={question}
onChange={(e) => {
setQuestion(e.target.value);
}}
></MathInput>
</div>
{/* Solution */}
<div
className={`space-y-2 ${isSolutionVisible ? "" : "invisible"}`}
>
<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>

{/* Bottom buttons */}
<div className="flex justify-evenly">
<DialogTrigger asChild>
<Button
onClick={handleDialogClose}
variant={"ghost"}
className="w-36 border border-black"
>
Close
</Button>
</DialogTrigger>
<Button onClick={handleSolutionVisible} className="w-36">
Hide Solution
</Button>
</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