-
-
Save covelitein/b4081a794abddf88b4db6dea431ce792 to your computer and use it in GitHub Desktop.
p2e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react' | |
import { useParams } from 'react-router-dom' | |
import { Header, Game, Chat } from '../components' | |
import { getGame, getScores } from '../services/blockchain' | |
import { setGlobalState, useGlobalState } from '../store' | |
import { getGroup } from '../services/chat' | |
import GameResult from '../components/GameResult' | |
const GamePlay = () => { | |
const { id } = useParams() | |
const [game] = useGlobalState('game') | |
const [scores] = useGlobalState('scores') | |
const [connectedAccount] = useGlobalState('connectedAccount') | |
const [loaded, setLoaded] = useState(false) | |
useEffect(() => { | |
const fetchData = async () => { | |
await getGame(id) | |
await getScores(id) | |
setLoaded(true) | |
const GROUP = await getGroup(`guid_${id}`) | |
setGlobalState('group', GROUP) | |
} | |
fetchData() | |
}, [id]) | |
return ( | |
loaded && ( | |
<> | |
<Header /> | |
<Game | |
game={game} | |
isPlayed={scores.some( | |
(score) => score.played && score.player == connectedAccount | |
)} | |
/> | |
<GameResult game={game} scores={scores} /> | |
<Chat gid={id} /> | |
</> | |
) | |
) | |
} | |
export default GamePlay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment