|
@@ -0,0 +1,44 @@
|
|
|
+import ms from "pretty-ms";
|
|
|
+import { dispatch } from "../../../domain/gameStore";
|
|
|
+import { useRecentGameInfo } from "../../../hooks/useGameInfo";
|
|
|
+import styles from "./HomePage.module.css";
|
|
|
+
|
|
|
+const RecentGames = () => {
|
|
|
+ const recent = useRecentGameInfo();
|
|
|
+
|
|
|
+ if (!recent || recent.length === 0) {
|
|
|
+ return <></>;
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.recentSection}>
|
|
|
+ <div className={styles.recentTitle}>Recent Games:</div>
|
|
|
+ {recent.map(({ gameId, gameMode, rounds, timer, player, numPlayers }) => (
|
|
|
+ <button
|
|
|
+ key={gameId}
|
|
|
+ type="button"
|
|
|
+ className={styles.recentItem}
|
|
|
+ onClick={() => dispatch.goToLobby(gameId)}
|
|
|
+ >
|
|
|
+ <div>
|
|
|
+ {gameMode
|
|
|
+ .split("_")
|
|
|
+ .map(part => part[0].toUpperCase() + part.slice(1).toLowerCase())
|
|
|
+ .join(" ")}
|
|
|
+ ,
|
|
|
+ {rounds} round(s),
|
|
|
+ {ms(timer * 1000)}
|
|
|
+ </div>
|
|
|
+ <div className={styles.recentPlayerInfo}>
|
|
|
+ <div className={styles.recentPlayerName}>
|
|
|
+ {player ?? "(no players)"}
|
|
|
+ </div>
|
|
|
+ {numPlayers > 1 ? `+${numPlayers - 1}` : ""}
|
|
|
+ </div>
|
|
|
+ </button>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default RecentGames;
|