Skip to content

Commit 3bb0463

Browse files
committed
Don't load all stats to display rating
1 parent f5d406b commit 3bb0463

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/User.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { makeStyles, useTheme } from "@material-ui/core/styles";
22
import Security from "@material-ui/icons/Security";
33

4+
import { BASE_RATING } from "../game";
45
import useFirebaseRef from "../hooks/useFirebaseRef";
5-
import useStats from "../hooks/useStats";
66
import { getColor } from "../util";
77

88
const useStyles = makeStyles((theme) => ({
@@ -23,7 +23,9 @@ function User({ id, style, component, render, showRating, ...other }) {
2323
const classes = useStyles();
2424

2525
const [user, loading] = useFirebaseRef(`users/${id}`);
26-
const [stats, loadingStats] = useStats(showRating ? id : null);
26+
const [rating, loadingRating] = useFirebaseRef(
27+
showRating ? `userStats/${id}/${showRating}/rating` : null
28+
);
2729

2830
if (loading) {
2931
return null;
@@ -41,7 +43,7 @@ function User({ id, style, component, render, showRating, ...other }) {
4143
>
4244
{showRating && (
4345
<span className={classes.rating}>
44-
{loadingStats ? "⋯" : Math.round(stats[showRating].rating)}
46+
{loadingRating ? "⋯" : Math.round(rating ?? BASE_RATING)}
4547
</span>
4648
)}
4749
{user.admin && (

0 commit comments

Comments
 (0)