From cdf26551502db8e106606c29d802878a4253e6ce Mon Sep 17 00:00:00 2001 From: Andrew Casal Date: Thu, 24 Oct 2024 14:31:34 -0400 Subject: [PATCH] cleanup --- .../ChallengeModal/ChallengeModal.tsx | 19 ++----- .../LanguagePicker/LanguagePicker.tsx | 26 ++++----- src/views/Game/GameDock.tsx | 55 +++++++++---------- src/views/HelpFlows/ModalHelp.tsx | 17 ++++++ src/views/Play/Play.tsx | 44 +++++++-------- 5 files changed, 81 insertions(+), 80 deletions(-) diff --git a/src/components/ChallengeModal/ChallengeModal.tsx b/src/components/ChallengeModal/ChallengeModal.tsx index e01ba8f4d6..26338de035 100644 --- a/src/components/ChallengeModal/ChallengeModal.tsx +++ b/src/components/ChallengeModal/ChallengeModal.tsx @@ -18,7 +18,6 @@ import * as React from "react"; import * as data from "@/lib/data"; import * as player_cache from "@/lib/player_cache"; -import * as DynamicHelp from "react-dynamic-help"; import { OgsResizeDetector } from "@/components/OgsResizeDetector"; import { browserHistory } from "@/lib/ogsHistory"; @@ -62,6 +61,7 @@ import { saveTimeControlSettings, updateSystem, } from "@/components/TimeControl/TimeControlUpdates"; +import { ActivateTooltip } from "@/views/HelpFlows/ModalHelp"; export type ChallengeDetails = rest_api.ChallengeDetails; @@ -1780,20 +1780,9 @@ export class ChallengeModalBody extends React.Component< )} {mode === "computer" && ( - - {(value) => { - const { ref: modalHelpIntro } = - value.registerTargetItem("modal-help-intro"); - return ( - value.triggerFlow("modal-help")} - > - {_("Computer")} - - ); - }} - + + {_("Computer")} + )} diff --git a/src/components/LanguagePicker/LanguagePicker.tsx b/src/components/LanguagePicker/LanguagePicker.tsx index 19b18407b6..815d4c3a1f 100644 --- a/src/components/LanguagePicker/LanguagePicker.tsx +++ b/src/components/LanguagePicker/LanguagePicker.tsx @@ -36,19 +36,19 @@ function language_sorter(a: string, b: string) { return 0; } -export const LanguagePicker = () => ( - - {({ showModal }) => ( - showModal(ModalTypes.LanguagePicker)} - > - - {languages[current_language]} - - )} - -); +export const LanguagePicker = () => { + const { showModal } = React.useContext(ModalContext); + + return ( + showModal(ModalTypes.LanguagePicker)} + > + + {languages[current_language]} + + ); +}; export const LanguagePickerModal = () => { const { hideModal } = React.useContext(ModalContext); diff --git a/src/views/Game/GameDock.tsx b/src/views/Game/GameDock.tsx index 3092d9216b..3fcc505c58 100644 --- a/src/views/Game/GameDock.tsx +++ b/src/views/Game/GameDock.tsx @@ -39,6 +39,22 @@ import { useUserIsParticipant } from "./GameHooks"; import { useGoban } from "./goban_context"; import { Tooltip } from "../../components/Tooltip"; import { ModalContext, ModalTypes } from "@/components/Modal/ModalContext"; +import { GobanEngine, GobanRenderer } from "goban"; + +const handleForkGameClick = ( + showModal: (type: ModalTypes, props?: any) => void, + user: rest_api.UserConfig, + engine: GobanEngine, + goban: GobanRenderer, +) => { + if (!user.anonymous && !engine.rengo && !goban.isAnalysisDisabled()) { + if (!goban) { + return; + } + + showModal(ModalTypes.Fork, { goban }); + } +}; interface DockProps { annulled: boolean; @@ -92,6 +108,7 @@ export function GameDock({ const phase = engine.phase; const user = useUser(); + const { showModal } = React.useContext(ModalContext); const tooltipRequired = preferences.get("dock-delay") === MAX_DOCK_DELAY; @@ -441,34 +458,16 @@ export function GameDock({ - - {({ showModal }) => ( - { - if ( - !user.anonymous && - !engine.rengo && - !goban.isAnalysisDisabled() - ) { - if (!goban) { - return; - } - - return showModal(ModalTypes.Fork, { - goban, - }); - } - }} - className={ - user.anonymous || engine.rengo || goban.isAnalysisDisabled() - ? "disabled" - : "" - } - > - {_("Fork game")} - - )} - + handleForkGameClick(showModal, user, engine, goban)} + className={ + user.anonymous || engine.rengo || goban.isAnalysisDisabled() + ? "disabled" + : "" + } + > + {_("Fork game")} + diff --git a/src/views/HelpFlows/ModalHelp.tsx b/src/views/HelpFlows/ModalHelp.tsx index 95c05fd773..91e51c3018 100644 --- a/src/views/HelpFlows/ModalHelp.tsx +++ b/src/views/HelpFlows/ModalHelp.tsx @@ -20,6 +20,7 @@ import * as React from "react"; import { HelpFlow, HelpItem } from "react-dynamic-help"; +import * as DynamicHelp from "react-dynamic-help"; export function ModalHelp(): JSX.Element { return ( @@ -30,3 +31,19 @@ export function ModalHelp(): JSX.Element { ); } + +interface ActivateTooltipProps { + children: React.ReactNode; + flow: string; + item: string; +} + +export const ActivateTooltip = ({ children, flow, item }: ActivateTooltipProps) => ( + + {(value) => { + const { ref: modalHelpIntro } = value.registerTargetItem(`${flow}-${item}`); + value.triggerFlow(flow); + return
{children}
; + }} +
+); diff --git a/src/views/Play/Play.tsx b/src/views/Play/Play.tsx index 4cd0787d40..a2b49c5566 100644 --- a/src/views/Play/Play.tsx +++ b/src/views/Play/Play.tsx @@ -61,6 +61,14 @@ import { ModalContext, ModalTypes } from "@/components/Modal/ModalContext"; const CHALLENGE_LIST_FREEZE_PERIOD = 1000; // Freeze challenge list for this period while they move their mouse on it +const handleComputerChallengeClick = (showModal: (type: ModalTypes, props?: any) => void) => { + if (bot_count() === 0) { + void alert.fire(_("Sorry, all bots seem to be offline, please try again later.")); + return; + } + showModal(ModalTypes.Challenge); +}; + interface PlayState { live_list: Array; correspondence_list: Array; @@ -822,30 +830,18 @@ export class Play extends React.Component<{}, PlayState> {
- {({ showModal }) => { - return ( - - ); - }} + {({ showModal }) => ( + + )}