Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Casal authored and Andrew Casal committed Oct 24, 2024
1 parent 58d1d87 commit cdf2655
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 80 deletions.
19 changes: 4 additions & 15 deletions src/components/ChallengeModal/ChallengeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -62,6 +61,7 @@ import {
saveTimeControlSettings,
updateSystem,
} from "@/components/TimeControl/TimeControlUpdates";
import { ActivateTooltip } from "@/views/HelpFlows/ModalHelp";

export type ChallengeDetails = rest_api.ChallengeDetails;

Expand Down Expand Up @@ -1780,20 +1780,9 @@ export class ChallengeModalBody extends React.Component<
</span>
)}
{mode === "computer" && (
<DynamicHelp.Api.Consumer>
{(value) => {
const { ref: modalHelpIntro } =
value.registerTargetItem("modal-help-intro");
return (
<span
ref={modalHelpIntro}
onClick={() => value.triggerFlow("modal-help")}
>
{_("Computer")}
</span>
);
}}
</DynamicHelp.Api.Consumer>
<ActivateTooltip flow="modal-help" item="intro">
<span>{_("Computer")}</span>
</ActivateTooltip>
)}
</h2>
</div>
Expand Down
26 changes: 13 additions & 13 deletions src/components/LanguagePicker/LanguagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ function language_sorter(a: string, b: string) {
return 0;
}

export const LanguagePicker = () => (
<ModalContext.Consumer>
{({ showModal }) => (
<span
className="LanguagePicker fakelink"
onClick={() => showModal(ModalTypes.LanguagePicker)}
>
<i className="fa fa-language" />
{languages[current_language]}
</span>
)}
</ModalContext.Consumer>
);
export const LanguagePicker = () => {
const { showModal } = React.useContext(ModalContext);

return (
<span
className="LanguagePicker fakelink"
onClick={() => showModal(ModalTypes.LanguagePicker)}
>
<i className="fa fa-language" />
{languages[current_language]}
</span>
);
};

export const LanguagePickerModal = () => {
const { hideModal } = React.useContext(ModalContext);
Expand Down
55 changes: 27 additions & 28 deletions src/views/Game/GameDock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -441,34 +458,16 @@ export function GameDock({
</a>
</Tooltip>
<Tooltip tooltipRequired={tooltipRequired} title={_("Fork game")}>
<ModalContext.Consumer>
{({ showModal }) => (
<a
onClick={() => {
if (
!user.anonymous &&
!engine.rengo &&
!goban.isAnalysisDisabled()
) {
if (!goban) {
return;
}

return showModal(ModalTypes.Fork, {
goban,
});
}
}}
className={
user.anonymous || engine.rengo || goban.isAnalysisDisabled()
? "disabled"
: ""
}
>
<i className="fa fa-code-fork"></i> {_("Fork game")}
</a>
)}
</ModalContext.Consumer>
<a
onClick={() => handleForkGameClick(showModal, user, engine, goban)}
className={
user.anonymous || engine.rengo || goban.isAnalysisDisabled()
? "disabled"
: ""
}
>
<i className="fa fa-code-fork"></i> {_("Fork game")}
</a>
</Tooltip>
<Tooltip tooltipRequired={tooltipRequired} title={_("Call moderator")}>
<a onClick={alertModerator} className={user.anonymous ? "disabled" : ""}>
Expand Down
17 changes: 17 additions & 0 deletions src/views/HelpFlows/ModalHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -30,3 +31,19 @@ export function ModalHelp(): JSX.Element {
</HelpFlow>
);
}

interface ActivateTooltipProps {
children: React.ReactNode;
flow: string;
item: string;
}

export const ActivateTooltip = ({ children, flow, item }: ActivateTooltipProps) => (
<DynamicHelp.Api.Consumer>
{(value) => {
const { ref: modalHelpIntro } = value.registerTargetItem(`${flow}-${item}`);
value.triggerFlow(flow);
return <div ref={modalHelpIntro}>{children}</div>;
}}
</DynamicHelp.Api.Consumer>
);
44 changes: 20 additions & 24 deletions src/views/Play/Play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Challenge>;
correspondence_list: Array<Challenge>;
Expand Down Expand Up @@ -822,30 +830,18 @@ export class Play extends React.Component<{}, PlayState> {
</div>
<div className="automatch-row">
<ModalContext.Consumer>
{({ showModal }) => {
return (
<button
className="primary"
onClick={() => {
if (bot_count() === 0) {
void alert.fire(
_(
"Sorry, all bots seem to be offline, please try again later.",
),
);
return;
}
showModal(ModalTypes.Challenge);
}}
disabled={anon || warned}
>
<div className="play-button-text-root">
<i className="fa fa-desktop" /> {_("Computer")}
<span className="time-per-move"></span>
</div>
</button>
);
}}
{({ showModal }) => (
<button
className="primary"
onClick={() => handleComputerChallengeClick(showModal)}
disabled={anon || warned}
>
<div className="play-button-text-root">
<i className="fa fa-desktop" /> {_("Computer")}
<span className="time-per-move"></span>
</div>
</button>
)}
</ModalContext.Consumer>
<button
className="primary"
Expand Down

0 comments on commit cdf2655

Please sign in to comment.