Refactor Study Desk application structure
This commit is contained in:
parent
faaccf8a7e
commit
089439ed90
145 changed files with 8087 additions and 3412 deletions
|
|
@ -27,6 +27,7 @@ interface QuizAttempt {
|
|||
score: number;
|
||||
maxScore: number;
|
||||
answersJson: string;
|
||||
reviewSnapshotJson?: string | null;
|
||||
isPartialRetake: boolean;
|
||||
completedAt: string;
|
||||
}
|
||||
|
|
@ -42,6 +43,8 @@ interface QuizData {
|
|||
currentIndex: number;
|
||||
orderJson: string;
|
||||
answersJson: string | null;
|
||||
sessionId: string;
|
||||
revision: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
|
|
@ -60,13 +63,23 @@ export default function QuizStudyPage() {
|
|||
|
||||
async function handleRestart() {
|
||||
if (!quiz) return;
|
||||
|
||||
// Clear progress in database
|
||||
await fetch("/api/progress", {
|
||||
method: "DELETE",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ contentType: "QUIZ", contentId: quiz.id, mode: "SEQUENTIAL" })
|
||||
}).catch(() => {});
|
||||
const progress = quiz.progress.find((item) => item.mode === "SEQUENTIAL");
|
||||
if (progress) {
|
||||
const response = await fetch("/api/progress", {
|
||||
method: "DELETE",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
contentType: "QUIZ",
|
||||
contentId: quiz.id,
|
||||
mode: "SEQUENTIAL",
|
||||
sessionId: progress.sessionId,
|
||||
}),
|
||||
}).catch(() => null);
|
||||
if (!response?.ok) {
|
||||
window.alert("The quiz could not be restarted. Your saved progress was kept.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear locally and force remount
|
||||
setQuiz({ ...quiz, progress: [] });
|
||||
|
|
@ -104,7 +117,8 @@ export default function QuizStudyPage() {
|
|||
}, [quizId, classSlug, router]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchQuizAndAttempts();
|
||||
const timer = window.setTimeout(() => void fetchQuizAndAttempts(), 0);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [fetchQuizAndAttempts]);
|
||||
|
||||
const [showTopics, setShowTopics] = useState(false);
|
||||
|
|
@ -221,6 +235,7 @@ export default function QuizStudyPage() {
|
|||
key={restartKey}
|
||||
quiz={quiz}
|
||||
retakeIds={retakeIds}
|
||||
sessionKey={restartKey}
|
||||
onFinished={() => {
|
||||
router.push(`/${classSlug}/quizzes`);
|
||||
}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue