From f5d1d84b81497274475c9c38311d5a16be20713a Mon Sep 17 00:00:00 2001 From: Stefan Schermann Date: Wed, 6 Sep 2023 12:47:48 +0200 Subject: [PATCH 1/2] fix rejoining unstarted private tournaments withdrawing from an unstarted tournament removes the user, which requires entering the password again on rejoin ctrl.tournament is overwritten in onReload, so an explicit reference is required for mithril to detect the removal of tournament.me --- src/lichess/tournament.ts | 2 +- src/ui/tournament/detail/tournamentView.tsx | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lichess/tournament.ts b/src/lichess/tournament.ts index 05551db931..18d0dea76b 100644 --- a/src/lichess/tournament.ts +++ b/src/lichess/tournament.ts @@ -5,5 +5,5 @@ export function isIn(data: Tournament): boolean { } export function previouslyJoined(data: Tournament): boolean { - return data.me != null + return !!data.me } diff --git a/src/ui/tournament/detail/tournamentView.tsx b/src/ui/tournament/detail/tournamentView.tsx index 8f0dc3559c..c0f74cc20b 100644 --- a/src/ui/tournament/detail/tournamentView.tsx +++ b/src/ui/tournament/detail/tournamentView.tsx @@ -75,7 +75,7 @@ export function renderFooter(ctrl: TournamentCtrl): Mithril.Child { } : h.fragment({key: 'noChat'}, []) } - { ctrl.hasJoined ? withdrawButton(ctrl, t) : joinButton(ctrl, t) } + { ctrl.hasJoined ? withdrawButton(ctrl) : joinButton(ctrl) } ) } @@ -181,7 +181,8 @@ function tournamentSpotlightInfo(spotlight: Spotlight) { ) } -function joinButton(ctrl: TournamentCtrl, t: Tournament) { +function joinButton(ctrl: TournamentCtrl) { + const t = ctrl.tournament if (!session.isConnected() || t.isFinished || settings.game.supportedVariants.indexOf(t.variant) < 0 || @@ -189,9 +190,9 @@ function joinButton(ctrl: TournamentCtrl, t: Tournament) { (t.teamBattle && t.teamBattle.joinWith.length === 0)) { return h.fragment({key: 'noJoinButton'}, []) } - const action = ((t.private || t.teamBattle) && !previouslyJoined(t)) ? - () => joinForm.open(ctrl) : - () => ctrl.join() + const action = () => ((ctrl.tournament.private || ctrl.tournament.teamBattle) && !previouslyJoined(ctrl.tournament)) ? + joinForm.open(ctrl) : + ctrl.join() return (