Skip to content

Commit

Permalink
Merge pull request #2806 from GreenAsJade/turn_off_rdh_on_mobile
Browse files Browse the repository at this point in the history
Provide `isDesktop` hook, use it to turn of RDH on not-desktop
  • Loading branch information
anoek authored Sep 5, 2024
2 parents 94261fc + 535093d commit 5036cec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/OgsHelpProvider/OgsHelpProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as data from "data";

import { HelpProvider, HelpPopupDictionary } from "react-dynamic-help";
import * as DynamicHelp from "react-dynamic-help";
import { useIsDesktop, useUser } from "hooks";

const helpPopupDictionary: HelpPopupDictionary = {
"Skip this topic": pgettext("A button to dismiss a help popup topic", "Skip this topic"),
Expand All @@ -39,10 +40,13 @@ type OgsHelpProviderProps = {
*/

export function OgsHelpProvider(props: OgsHelpProviderProps): JSX.Element {
// RDH needs work to support mobile layouts
const isDesktop = useIsDesktop();

const [storageLoaded, setStorageLoaded] = React.useState(false);

const debugDynamicHelp = data.get("debug-dynamic-help", false);
const user = data.get("config.user");
const user = useUser();

// Make help system use our server-based storage, to achieve logged-in-user-specific help state.

Expand Down Expand Up @@ -82,7 +86,7 @@ export function OgsHelpProvider(props: OgsHelpProviderProps): JSX.Element {
<HelpProvider
dictionary={helpPopupDictionary}
storageApi={dynamicHelpStorage}
storageReady={storageLoaded}
storageReady={storageLoaded && isDesktop} // hack to turn it off for mobile
debug={debugDynamicHelp}
>
{props.children}
Expand Down
16 changes: 16 additions & 0 deletions src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,19 @@ export function useRefresh(): () => void {
export function useMainGoban(): Goban | null {
return (window as any)["global_goban"];
}

export const useIsDesktop = () => {
const [isDesktop, setIsDesktop] = React.useState(true);

React.useEffect(() => {
const mediaQuery = window.matchMedia("(min-width: 850px)");
const handleResize = () => setIsDesktop(mediaQuery.matches);

handleResize(); // Check on mount
mediaQuery.addEventListener("change", handleResize); // Listen for changes

return () => mediaQuery.removeEventListener("change", handleResize);
}, []);

return isDesktop;
};

0 comments on commit 5036cec

Please sign in to comment.