Skip to content

Commit 6ac696f

Browse files
committed
chore: cleanup streaks + delay show results
1 parent 9d203ed commit 6ac696f

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

client/src/lib/storage.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,19 @@ function savePlayRecord(data: PlayRecord) {
6161

6262
export function updateStreak(
6363
day: number,
64-
time: [number, number],
6564
): { daysPlayed: number; currentStreak: number; bestStreak: number } | null {
65+
const finishDay = getDayNumber();
66+
const now = new Date();
67+
68+
let time: [number, number];
69+
if (finishDay === day) {
70+
time = [now.getHours(), now.getMinutes()];
71+
} else if (finishDay === day + 1 && now.getHours() < 3) {
72+
time = [24 + now.getHours(), now.getMinutes()];
73+
} else {
74+
return null;
75+
}
76+
6677
const record = getPlayRecord();
6778
if (day in record) return null;
6879
record[day] = time;

client/src/pages/ArchivePage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ function buildMonthGroups(maxDay: number, completed: Set<number>): MonthGroup[]
6262
}
6363

6464
export function ArchivePage() {
65-
const today = getDayNumber();
66-
const maxDay = today;
65+
const maxDay = getDayNumber();
6766
const completed = getCompletedDaySet();
6867
const months = buildMonthGroups(maxDay, completed);
6968

@@ -104,7 +103,10 @@ function MonthCalendar({ year, month, firstDayOfWeek, daysInMonth, puzzleDays }:
104103
const info = puzzleDays.get(dayOfMonth);
105104
if (!info) {
106105
return (
107-
<div key={dayOfMonth} class="aspect-square flex items-center justify-center text-xs text-gray-200">
106+
<div
107+
key={dayOfMonth}
108+
class="aspect-square flex items-center justify-center text-xs text-gray-200"
109+
>
108110
{dayOfMonth}
109111
</div>
110112
);

client/src/pages/GamePage.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ function GameOrResults({ day, puzzle }: { day: number; puzzle: string }) {
6262
day={day}
6363
puzzle={puzzle}
6464
onComplete={(words) => {
65-
const gameResult = updateDayResults(day, words);
6665
fetch(`/api/dailies/${day}/results`, {
6766
method: "POST",
6867
headers: { "Content-Type": "application/json" },
@@ -73,19 +72,13 @@ function GameOrResults({ day, puzzle }: { day: number; puzzle: string }) {
7372
}),
7473
});
7574

76-
const finishDay = getDayNumber();
77-
const now = new Date();
78-
79-
let streaks: Streaks | null = null;
80-
if (finishDay === day) {
81-
streaks = updateStreak(day, [now.getHours(), now.getMinutes()]);
82-
} else if (finishDay === day + 1 && now.getHours() < 3) {
83-
streaks = updateStreak(day, [24 + now.getHours(), now.getMinutes()]);
84-
}
75+
const gameResult = updateDayResults(day, words);
76+
const streaks = updateStreak(day);
8577

86-
// TODO Game errors if not switched immediately after onComplete
87-
// what if fetch isn't called in time for data to show in result charts
88-
setResults({ gameResult, streaks });
78+
// hacky, wait until post to show results
79+
setTimeout(() => {
80+
setResults({ gameResult, streaks });
81+
}, 300);
8982
}}
9083
/>
9184
);

0 commit comments

Comments
 (0)