Skip to content

Commit

Permalink
Improve recent matches to load it from the DB (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrvecera authored Oct 20, 2022
1 parent ce70e14 commit 176d3e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/web/src/components/main-home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MainHome: React.FC = () => {
}
}, []);

const cardStyle = { width: 240, height: 265 };
const cardStyle = { width: 240, height: 275 };

return (
<Row>
Expand Down
13 changes: 9 additions & 4 deletions packages/web/src/pages/recent-matches/recent-matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
limit,
orderBy,
query,
getCountFromServer,
doc,
getDoc,
} from "firebase/firestore";
import { ColumnsType } from "antd/es/table";
import {
Expand Down Expand Up @@ -46,20 +47,24 @@ const RecentMatches: React.FC = () => {

try {
const matchesRef = collection(getFirestore(), "matches");
const docTotalMatchesRef = doc(getFirestore(), "stats", "totalStoredMatches");

const q = query(matchesRef, orderBy("completiontime", "desc"), limit(20));

const [snapshot, querySnapshot] = await Promise.all([
getCountFromServer(matchesRef),
const [docSnapTotalMatches, querySnapshot] = await Promise.all([
getDoc(docTotalMatchesRef),
getDocs(q),
]);
setTotalMatches(snapshot.data().count);

const gamesData: Array<Record<string, any>> = [];
querySnapshot.forEach((doc) => {
gamesData.push(doc.data());
});

if (docSnapTotalMatches.exists()) {
setTotalMatches(docSnapTotalMatches.data()?.count);
}

setMatchRecords(gamesData);
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 176d3e4

Please sign in to comment.