Skip to content

Commit 0916101

Browse files
committed
Quiz restart now properly refetches previous leaderboard submissions; Fixed text wrap on update submission modal
1 parent 007be39 commit 0916101

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

Diff for: frontend/app/(pages)/quiz/[...query]/page.tsx

+26-14
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,6 @@ export default function Quiz({ params }: { params: { query: string[] } }) {
165165
router.push("/");
166166
}
167167

168-
// See if the player has a UUID in local storage, if not, create one and store it
169-
let uuid: string | null = localStorage.getItem("quizPlayerUUID");
170-
if (uuid) {
171-
// If there is a UUID, retrieve the player's previous leaderboard entry (if any)
172-
const entry: TimeAttackEntry | SurvivalEntry | null = await getPastPlayerLeaderboardEntry(quizId, uuid, shareableToken || undefined);
173-
if (entry) setPreviousLeaderboardEntry(entry);
174-
} else {
175-
uuid = uuidv4(); // Generate a new one
176-
localStorage.setItem("quizPlayerUUID", uuid);
177-
}
178-
setPlayerUUID(uuid);
179-
180168
// See if the player has a stored preference for playing SFX in local storage
181169
let sfxPref: string | null = localStorage.getItem("quizSFX");
182170
if (!sfxPref) {
@@ -209,6 +197,30 @@ export default function Quiz({ params }: { params: { query: string[] } }) {
209197
getPageData();
210198
}, []);
211199

200+
// Handles the generation/retrieval of the player's UUID and previous leaderboard entry (for updating)
201+
// Runs on component mount and whenever a quiz is restarted after a score is submitted.
202+
useEffect(() => {
203+
const setUuidAndGetPreviousEntry = async () => {
204+
205+
if (scoreSubmitted) return;
206+
// When scoreSubmitted changes from true to false, the player submitted a score and clicked "Play Again".
207+
// This means they will have a new previous entry, and we need to update the state accordingly.
208+
209+
// See if the player has a UUID in local storage, if not, create one and store it
210+
let uuid: string | null = localStorage.getItem("quizPlayerUUID");
211+
if (uuid) {
212+
// If there is a UUID, retrieve the player's previous leaderboard entry (if any)
213+
const entry: TimeAttackEntry | SurvivalEntry | null = await getPastPlayerLeaderboardEntry(quizId, uuid, shareableToken || undefined);
214+
if (entry) setPreviousLeaderboardEntry(entry);
215+
} else {
216+
uuid = uuidv4(); // Generate a new one
217+
localStorage.setItem("quizPlayerUUID", uuid);
218+
}
219+
setPlayerUUID(uuid);
220+
}
221+
setUuidAndGetPreviousEntry();
222+
}, [scoreSubmitted]);
223+
212224
// ----- DATA HELPERS -----
213225

214226
const getNextMessage = async () => {
@@ -736,7 +748,7 @@ export default function Quiz({ params }: { params: { query: string[] } }) {
736748
</>);
737749
} else if (previousLeaderboardEntry && !noResubmit) {
738750
modalContent = (<>
739-
<div className="w-full mt-3 text-center text-2xl font-semibold">
751+
<div className="w-full mt-5 text-center text-2xl font-semibold">
740752
Update previous entry?
741753
</div>
742754
<div className="w-full text-center text-lg mt-3 text-zinc-300 font-light">
@@ -746,7 +758,7 @@ export default function Quiz({ params }: { params: { query: string[] } }) {
746758
</span>
747759
</div>
748760
<div className="grid grid-cols-2 gap-2 mt-6 mb-5 mx-7">
749-
<button className="grow btn btn-lg bg-black border border-zinc-900 text-zinc-400 font-light"
761+
<button className="grow btn btn-lg bg-black border border-zinc-900 text-zinc-400 font-light whitespace-nowrap"
750762
onClick={() => setNoResubmit(true)}>
751763
No Thanks
752764
</button>

Diff for: frontend/app/components/modals/CreateQuizModal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default function CreateQuizModal({ groupChatId, groupChatName, modalDomId
8686
});
8787
}
8888

89-
// Display the response message for 3 seconds, then close the modal and re-fetch the data.
89+
// Display the response message for 1.5 seconds, then close the modal and re-fetch the data.
9090
setTimeout(() => {
9191
if (isModalOpen(modalDomId)) {
9292
toggleModal(modalDomId);
@@ -101,7 +101,7 @@ export default function CreateQuizModal({ groupChatId, groupChatName, modalDomId
101101
setReloadCounter(c => c + 1) // Reload the parent page to display the new group chat after 0.5s.
102102
}, 500);
103103
}
104-
}, 3000);
104+
}, 1500);
105105

106106
setCreating(false);
107107
}

0 commit comments

Comments
 (0)