-
+
{finishResult?.winner === true && showWinText && (
Winner!
)}
-
-
{truncatedAddress}
- {/*{icon}*/}
+ {address ? (
+
+ ) : (
+
+ )}
+
+ {address ? (
+
+ {/*
{playerName} {moves && (move)}
*/}
+
{truncatedAddress}
+
+ ) : (
+
Waiting...
+ )}
+
{playerType}
);
diff --git a/components/GameResult/ScoreCard/ScoreCardProps.ts b/components/GameResult/ScoreCard/ScoreCardProps.ts
index e32e3de..8425360 100644
--- a/components/GameResult/ScoreCard/ScoreCardProps.ts
+++ b/components/GameResult/ScoreCard/ScoreCardProps.ts
@@ -4,10 +4,12 @@ import { PlayerI } from 'types/game';
import { PlayerPropsI } from '../../Player/PlayerProps'
export interface IScoreCardProps extends PlayerPropsI{
playerResult: {
- address?: string | null;
- playerType?: React.ReactNode;
- moves?: boolean;
- } | null;
+ players: ({
+ address?: string | null;
+ playerType?: React.ReactNode;
+ moves?: boolean;
+ } | null)[];
+ };
showWinText?: boolean,
finishResult: { winner: boolean; isDraw: boolean; cheatWin: boolean } | null
}
diff --git a/contexts/GameStateContext.tsx b/contexts/GameStateContext.tsx
index 71bb9ae..f27b4a0 100644
--- a/contexts/GameStateContext.tsx
+++ b/contexts/GameStateContext.tsx
@@ -1,62 +1,61 @@
-import React, { createContext, ReactNode, useContext, useState } from 'react';
-import { PlayerI } from '../types/game';
+import React, { createContext, ReactNode, useContext, useState } from 'react'
+import { PlayerI } from '../types/game'
export interface IGameStateContext {
finishResult: { winner: boolean; isDraw: boolean; cheatWin: boolean } | null;
- setFinishResult: (
- newFinishResult: {
- winner: boolean;
- isDraw: boolean;
- cheatWin: boolean;
- } | null,
- ) => void;
+ setFinishResult: (newFinishResult: {
+ winner: boolean; isDraw: boolean; cheatWin: boolean;
+ } | null) => void;
playerResult: {
- address?: string | null;
- playerType?: React.ReactNode;
- moves?: boolean;
- } | null;
- setPlayerResult: (newPlayerResult: {
- address?: string | null;
- playerType?: React.ReactNode;
- moves?: boolean;
+ players: ({
+ address?: string | null; playerType?: React.ReactNode; moves?: boolean;
+ } | null)[];
+ };
+ setPlayerResult: (newPlayersResult: {
+ players: ({
+ address?: string | null; playerType?: React.ReactNode; moves?: boolean;
+ } | null)[];
}) => void;
- // playerTypeResult: React.ReactNode | null;
}
export const GameStateContextDefault: IGameStateContext = {
- finishResult: null,
- setFinishResult: () => {},
- playerResult: null,
- setPlayerResult: () => {}, // playerTypeResult: null,
-};
-export const useGameStateContext = () => useContext(GameStateContext);
-export const GameStateContext = createContext
(GameStateContextDefault);
+ finishResult: null, setFinishResult: () => {},
+ playerResult: {
+ players: [{
+ address: null,
+ }],
+ }, setPlayerResult: () => {},
+}
+export const useGameStateContext = () => useContext(GameStateContext)
+export const GameStateContext = createContext(
+ GameStateContextDefault)
export const GameStateContextProvider: React.FC<{
children: React.ReactNode;
}> = ({ children }) => {
const [finishResult, setFinishResult] = useState<{
- winner: boolean;
- isDraw: boolean;
- cheatWin: boolean;
- } | null>(null);
- const [playerResult, setPlayerResult] = useState<{
- address?: string | null;
- playerType?: React.ReactNode;
- moves?: boolean;
- } | null>(null);
- const [playerTypeResult] = useState(null);
+ winner: boolean; isDraw: boolean; cheatWin: boolean;
+ } | null>(null)
+ const [playerResult, setPlayerResult] = useState<
+ IGameStateContext['playerResult']
+ >({
+ players: [
+ {
+ address: null,
+ playerType: null,
+ moves: false,
+ },
+ ],
+ });
+ const [playerTypeResult] = useState(null)
// TODO NEXT STEP habdevs 02/09/23
const contextValue: IGameStateContext = {
- finishResult,
- setFinishResult,
- playerResult,
- setPlayerResult,
- // playerTypeResult,
- };
- console.log('CONTEXT setFinishResult', setFinishResult);
- console.log('CONTEXT finishResult', finishResult);
- console.log('CONTEXT setPlayerResult', setPlayerResult);
- console.log('CONTEXT PlayerResult', playerResult);
- return {children};
-};
+ finishResult, setFinishResult, playerResult, setPlayerResult,
+ }
+ console.log('CONTEXT setFinishResult', setFinishResult)
+ console.log('CONTEXT finishResult', finishResult)
+ console.log('CONTEXT setPlayerResult', setPlayerResult)
+ console.log('CONTEXT PlayerResult', playerResult)
+ return {children}
+}