Skip to content

Self-hosted, plugin-based server management.

780 B
Raw Blame
import * as React from "react";
import { isElectron } from "@/lib/electron";

const MOBILE_BREAKPOINT = 768;

/** Phone layout below the breakpoint. The desktop app always stays desktop. */
export function useIsMobile() {
  const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
    undefined,
  );

  React.useEffect(() => {
    if (isElectron()) {
      setIsMobile(false);
      return;
    }
    const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
    const onChange = () => {
      setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
    };
    mql.addEventListener("change", onChange);
    setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
    return () => mql.removeEventListener("change", onChange);
  }, []);

  return !!isMobile;
}