import React, {useState, useRef, useLayoutEffect} from 'react'; import twemoji from 'twemoji'; import ReactRouter from 'react-router'; import {GameState, useListener} from './GamesUtil'; import './GamePage.css'; import Game from './Game'; import {getUID} from './util'; function GamePage(props: ReactRouter.RouteComponentProps<{id: string}>) { let [game, setGame] = useState<[string, GameState]|undefined>(undefined); let history = useRef<[number, string, string][]>([]); useListener((newGames) => { let newGame = newGames.find((gamePair) => gamePair[0] === props.match.params.id); setGame(newGame); console.log(newGame); if (newGame !== undefined && newGame[1].start_delay < 0 && newGame[1].end_delay > 8) { history.current.unshift([getUID(), newGame[1].update_emoji, newGame[1].update_text]); if (history.current.length > 8) { history.current.pop(); } } }); if (game === undefined) { return
The game you're looking for either doesn't exist or has already ended.
} return (
{ history.current.length > 0 ? : null }
); } function GameHistory(props: {history: [number, string, string][]}) { let self = useRef(null); useLayoutEffect(() => { if (self.current) { twemoji.parse(self.current); } }) return (
History
{props.history.map((update) => (
{update[1]}
{update[2]}
))}
); } export default GamePage;