From 9f95699435f12c4ba747dcb850ff1439ccc4fe3f Mon Sep 17 00:00:00 2001 From: Reqwey <50829219+Reqwey@users.noreply.github.com> Date: Mon, 25 Sep 2023 20:31:06 +0800 Subject: [PATCH] [fix] checkbox status loss when folded --- client/components/game/LeaderBoard.tsx | 138 ++++++++++++++----------- 1 file changed, 78 insertions(+), 60 deletions(-) diff --git a/client/components/game/LeaderBoard.tsx b/client/components/game/LeaderBoard.tsx index b4a93d5..aff0341 100644 --- a/client/components/game/LeaderBoard.tsx +++ b/client/components/game/LeaderBoard.tsx @@ -92,18 +92,33 @@ export default function LeaderBoard(props: LeaderBoardProps) { setGameDockExpand(!gameDockExpand); }} > - {warringStatesMode && ( - {t('country')} - )} - {gameDockExpand && checkedPlayers && setCheckedPlayers && ( - {t('view')} - )} - {gameDockExpand ? ( - {t('player')} - ) : ( - - )} - + + {t('country')} + + + {t('view')} + + + {t('player')} + + {t('army')} {t('land')} @@ -116,57 +131,60 @@ export default function LeaderBoard(props: LeaderBoardProps) { {WarringStates[player.color]} )} - {gameDockExpand && checkedPlayers && setCheckedPlayers && ( - - { - if (event.target.checked) { - let newCheckedPlayers = [ - ...checkedPlayers, - { - username: player.username, - color: player.color, - } as UserData, - ]; - setCheckedPlayers(newCheckedPlayers); - } else { - setCheckedPlayers( - checkedPlayers.filter( - (p) => p.color !== player.color - ) - ); - } - }} - /> - - )} - {gameDockExpand ? ( - { - setGameDockExpand(!gameDockExpand); - }} - > - {player.username} - - ) : ( - + { - setGameDockExpand(!gameDockExpand); + onChange={(event: any) => { + if (!checkedPlayers || !setCheckedPlayers) return; + if (event.target.checked) { + let newCheckedPlayers = [ + ...(checkedPlayers as UserData[]), + { + username: player.username, + color: player.color, + } as UserData, + ]; + setCheckedPlayers(newCheckedPlayers); + } else { + setCheckedPlayers( + checkedPlayers.filter((p) => p.color !== player.color) + ); + } }} - > - )} + /> + + { + setGameDockExpand(!gameDockExpand); + }} + > + {player.username} + + { + setGameDockExpand(!gameDockExpand); + }} + > {