Skip to content

Commit

Permalink
refactor account check into recordStats
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed Nov 1, 2024
1 parent 2205f93 commit b6f28f9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 1 addition & 2 deletions client/multiplayer/room.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import account from '../scripts/accounts.js';
import questionStats from '../scripts/auth/question-stats.js';
import api from '../scripts/api/index.js';
import audio from '../audio/index.js';
Expand Down Expand Up @@ -332,7 +331,7 @@ async function giveAnswer ({ celerity, directive, directedPrompt, givenAnswer, p
sortPlayerListGroup();
}

if (directive !== 'prompt' && userId === USER_ID && await account.getUsername()) {
if (directive !== 'prompt' && userId === USER_ID) {
questionStats.recordTossup(tossup, score > 0, score, perQuestionCelerity, true);
}

Expand Down
4 changes: 2 additions & 2 deletions client/multiplayer/room.min.js

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions client/scripts/auth/question-stats.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import account from '../accounts.js';

export default class questionStats {
static recordBonus (bonus, pointsPerPart) {
static async recordBonus (bonus, pointsPerPart) {
if (!(await account.getUsername())) {
return;
}

fetch('/auth/question-stats/record-bonus', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
Expand All @@ -14,7 +18,11 @@ export default class questionStats {
});
}

static recordTossup (tossup, isCorrect, pointValue, celerity, multiplayer) {
static async recordTossup (tossup, isCorrect, pointValue, celerity, multiplayer) {
if (!(await account.getUsername())) {
return;
}

fetch('/auth/question-stats/record-tossup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
Expand Down
3 changes: 1 addition & 2 deletions client/singleplayer/tossups/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import account from '../../scripts/accounts.js';
import api from '../../scripts/api/index.js';
import questionStats from '../../scripts/auth/question-stats.js';
import audio from '../../audio/index.js';
Expand Down Expand Up @@ -150,7 +149,7 @@ async function next ({ packetLength, oldTossup, tossup: nextTossup, type }) {
document.getElementById('question-number-info').textContent = nextTossup.number;
document.getElementById('set-name-info').textContent = nextTossup.set.name;

if (type === 'next' && await account.getUsername()) {
if (type === 'next' && room.previous.userId === USER_ID) {
const pointValue = room.previous.isCorrect ? (room.previous.inPower ? room.previous.powerValue : 10) : (room.previous.endOfQuestion ? 0 : room.previous.negValue);
questionStats.recordTossup(room.previous.tossup, room.previous.isCorrect, pointValue, room.previous.celerity, false);
}
Expand Down
Loading

0 comments on commit b6f28f9

Please sign in to comment.