Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
feat(Quiz) : student quiz result view
Browse files Browse the repository at this point in the history
  • Loading branch information
kasterra committed Jun 2, 2024
1 parent bb26252 commit 306d4ad
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Modal from "~/components/Modal";
import styles from "./modal.module.css";
import formStyles from "~/components/common/form.module.css";
import TextInput from "~/components/Input/TextInput";
import { useParams } from "@remix-run/react";
import { useEffect, useState } from "react";
import { useAuth } from "~/contexts/AuthContext";
import { getQuizWithUserId } from "~/API/practice";

interface Props {
isOpen: boolean;
onClose: () => void;
}

const QuizResultModal = ({ isOpen, onClose }: Props) => {
const auth = useAuth();
const [isLoading, setIsLoading] = useState(true);
const params = useParams();
const [quizResult, setQuizResult] = useState<
{
gain_score: number | null;
id: number;
max_score: number;
title: string;
}[]
>([]);
useEffect(() => {
async function getData() {
const { data } = await getQuizWithUserId(
params.lectureId!,
auth.userId,
auth.token
);
setQuizResult(data);
setIsLoading(false);
}
getData();
}, []);
return isLoading ? null : (
<Modal
title="퀴즈 결과 조회"
subtitle="사용자의 퀴즈 결과를 확인합니다"
isOpen={isOpen}
onClose={onClose}
>
<form className={styles["modal-body"]}>
{quizResult.map((result, idx) => (
<TextInput
title={`Q${idx + 1}`}
name=""
value={`${
result.gain_score == null ? "점수없음" : result.gain_score
}/${result.max_score}`}
/>
))}
</form>
</Modal>
);
};

export default QuizResultModal;
16 changes: 16 additions & 0 deletions app/routes/_procted+/lectures+/$lectureId+/_layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { deleteProblem } from "~/API/problem";
import { deleteTestcase } from "~/API/testCase";
import DownloadMyCodesModal from "./DownloadMyCodesModal";
import { LinkElement } from "~/components/Aside/LinkElement";
import QuizResultModal from "./QuizResultModal";
const LectureDetail = () => {
const [isLoading, setIsLoading] = useState(true);
const [lectures, setLectures] = useState<LectureEntity[]>([]);
Expand Down Expand Up @@ -244,6 +245,7 @@ const PracticeDetail = ({
const [practiceDetail, setPracticeDetail] = useState<SimplePracticeDetail>();
const [isPracticeEditModalOpen, setIsPracticeEditModalOpen] = useState(false);
const [isProblemAddModalOpen, setIsProblemAddModalOpen] = useState(false);
const [isQuizResultModalOpen, setIsQuizResultModalOpen] = useState(false);
const [isFoldableOpen, setIsFoldableOpen] = useState(false);
const [hasQuiz, setHasQuiz] = useState(false);
const { lectureId } = useParams();
Expand Down Expand Up @@ -312,6 +314,14 @@ const PracticeDetail = ({
title={problem.title}
/>
))}
{auth.role === "student" && hasQuiz ? (
<ButtonElement
title="퀴즈 성적 보기"
onButtonClick={() => {
setIsQuizResultModalOpen(true);
}}
/>
) : null}
{auth.role === "professor" ? (
<>
<ButtonElement
Expand Down Expand Up @@ -384,6 +394,12 @@ const PracticeDetail = ({
practiceId={practiceDetail!.id}
/>
) : null}
{isQuizResultModalOpen ? (
<QuizResultModal
isOpen={isQuizResultModalOpen}
onClose={() => setIsQuizResultModalOpen(false)}
/>
) : null}
</>
);
};
Expand Down

0 comments on commit 306d4ad

Please sign in to comment.