generated from codersforcauses/django-nextjs-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
leonleerl
wants to merge
5
commits into
main
Choose a base branch
from
issue-61-Add_Question_Preview_Modal_Component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+292
−53
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c49619e
feat(question): add Preview Modal
leonleerl a351e2c
fix(pagination, data-grid): prettier code style modification
leonleerl befe8c8
chore(question): add comment for props
leonleerl 7218402
fix(question): add import
leonleerl 40f6466
fix(preview modal): remain the buttons at the bottom; make the modal …
leonleerl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,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> | ||
</> | ||
); | ||
} |
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,3 +1,5 @@ | ||
import { PaginationProps } from "@/types/question"; | ||
|
||
export function Pagination({ | ||
totalPages, | ||
currentPage, | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Yunho. I follow the style-guide.md. It says the folder name in /Components should use PascalCase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, hh, my fault!