Skip to content

Instantly share code, notes, and snippets.

@covelitein
Created August 17, 2023 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save covelitein/b4081a794abddf88b4db6dea431ce792 to your computer and use it in GitHub Desktop.
Save covelitein/b4081a794abddf88b4db6dea431ce792 to your computer and use it in GitHub Desktop.
p2e
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