-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path:bd
49 lines (41 loc) · 1.45 KB
/
:bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { useQuizTaker } from "@/providers";
import * as Dialog from "@radix-ui/react-dialog";
import { useEffect, useState } from "react";
type CompleteDialogProps = {
handleReset: () => void;
};
const CompleteDialog = ({ handleReset }: CompleteDialogProps) => {
const { quizTaker } = useQuizTaker();
const { correctIds, incorrectIds, remainingIds } = quizTaker;
const [isOpen, setIsOpen] = useState(false);
useEffect(() => {
const isComplete = remainingIds.size === 0;
setIsOpen(isComplete);
}, [remainingIds.size]);
const handleClose = () => {
setIsOpen(false);
};
return (
<Dialog.Root open={isOpen}>
<Dialog.Content className="fixed flex flex-col items-center p-4 bg-gray-6 border-black border-[calc(1px)] rounded-3xl top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-40">
<Dialog.Title>Quiz Complete!</Dialog.Title>
<Dialog.Description className="m-4">{`Your score: ${
correctIds.size
} / ${correctIds.size + incorrectIds.size}`}</Dialog.Description>
<Dialog.Close
className="p-2 mb-1 w-3/4 rounded-3xl bg-gray-700 text-white"
onClick={handleReset}
>
Take Again
</Dialog.Close>
<Dialog.Close
className="p-2 w-3/4 rounded-3xl bg-gray-700 text-white"
onClick={handleClose}
>
Close
</Dialog.Close>
</Dialog.Content>
</Dialog.Root>
);
};
export { CompleteDialog };