Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump profile to last 100 games and fetch stale games #174

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ProfileGamesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function ProfileGamesTable({ userId, gamesWithScores, handleClickGame }) {
if (Object.keys(gamesWithScores).length === 0) {
return (
<Typography style={{ color: grey[400] }}>
No recent games to display…
No recent games in this category.
</Typography>
);
}
Expand Down
25 changes: 21 additions & 4 deletions src/pages/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import Select from "@mui/material/Select";
import Typography from "@mui/material/Typography";
import makeStyles from "@mui/styles/makeStyles";
import { useEffect, useMemo, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { Navigate, useParams } from "react-router-dom";

import Loading from "../components/Loading";
import ProfileGamesTable from "../components/ProfileGamesTable";
import ProfileName from "../components/ProfileName";
import Subheading from "../components/Subheading";
import UserStatistics from "../components/UserStatistics";
import firebase from "../firebase";
import firebase, { fetchStaleGame } from "../firebase";
import useFirebaseRefs from "../hooks/useFirebaseRefs";
import useStats from "../hooks/useStats";
import { computeState, hasHint, modes } from "../util";
Expand Down Expand Up @@ -73,7 +73,7 @@
.database()
.ref(`/userGames/${userId}`)
.orderByValue()
.limitToLast(50);
.limitToLast(100);
const update = (snapshot) => {
query.off("value", update);
setGames(snapshot.val() ?? {});
Expand All @@ -100,9 +100,26 @@
);
const [gameDataVals, loadingGameDataVals] = useFirebaseRefs(
useMemo(() => gameIds.map((gameId) => `gameData/${gameId}`), [gameIds]),
true,
);

/** @type {import("react").MutableRefObject<Set<string>>} */
const staleGamesFetched = useRef(new Set());

useEffect(() => {
if (!gameVals || !gameDataVals) return;
for (let i = 0; i < gameIds.length; i++) {
// Populate archived game data lazily if needed.
if (
gameVals[i].status === "done" &&
!gameDataVals[i] &&
!staleGamesFetched.current.has(gameIds[i])
) {
staleGamesFetched.current.add(gameIds[i]);
fetchStaleGame({ gameId: gameIds[i] });
}
}
}, [gameVals, gameDataVals]);

Check warning on line 121 in src/pages/ProfilePage.js

View workflow job for this annotation

GitHub Actions / Lint and Test

React Hook useEffect has a missing dependency: 'gameIds'. Either include it or remove the dependency array

if (redirect) {
return <Navigate push to={redirect} />;
}
Expand Down
Loading