MCPcopy Create free account
hub / github.com/code100x/chess / GameEndModal

Function GameEndModal

apps/frontend/src/components/GameEndModal.tsx:12–105  ·  view source on GitHub ↗
({
  blackPlayer,
  whitePlayer,
  gameResult,
})

Source from the content-addressed store, hash-verified

10}
11
12const GameEndModal: React.FC<ModalProps> = ({
13 blackPlayer,
14 whitePlayer,
15 gameResult,
16}) => {
17 const [isOpen, setIsOpen] = useState(true);
18
19 const closeModal = () => {
20 setIsOpen(false);
21 };
22
23 const PlayerDisplay = ({
24 player,
25 gameResult,
26 isWhite,
27 }: {
28 player?: { id: string; name: string };
29 gameResult: Result;
30 isWhite: boolean;
31 }) => {
32 const imageSrc = isWhite ? WhiteKing : BlackKing;
33 const borderColor =
34 gameResult === (isWhite ? Result.WHITE_WINS : Result.BLACK_WINS)
35 ? 'border-green-400'
36 : 'border-red-400';
37
38 return (
39 <div className="flex flex-col items-center">
40 <div className={`border-4 rounded-full p-2 ${borderColor}`}>
41 <img
42 src={imageSrc}
43 alt={`${isWhite ? 'White' : 'Black'} King`}
44 className="w-10 h-10"
45 />
46 </div>
47 <div className="text-center text-xm p-2">
48 <p className="text-white truncate w-24" title={getPlayerName(player)}>
49 {getPlayerName(player)}
50 </p>
51 </div>
52 </div>
53 );
54 };
55
56 const getWinnerMessage = (result: Result) => {
57 switch (result) {
58 case Result.BLACK_WINS:
59 return 'Black Wins!';
60 case Result.WHITE_WINS:
61 return 'White Wins!';
62 default:
63 return "It's a Draw";
64 }
65 };
66
67 const getPlayerName = (player: { id: string; name: string } | undefined) => {
68 return player ? player.name : 'Unknown';
69 };

Callers

nothing calls this directly

Calls 1

getWinnerMessageFunction · 0.85

Tested by

no test coverage detected