Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

1.1 KB
Raw Blame
import { useCallback, useEffect, useRef, useState } from 'react';

export const FIRST_TOUCH_HINT_DURATION_MS = 2500;

/**
 * Shows a short-lived hint once, when a canvas first receives a touch gesture.
 *
 * Canvas controls intentionally use `touch-action: none`, so a first finger
 * drag rotates the scene instead of scrolling the page. Keeping this state in
 * one hook makes that gesture explicit without changing the control itself.
 */
export default function useFirstTouchHint({ durationMs = FIRST_TOUCH_HINT_DURATION_MS } = {}) {
  const [visible, setVisible] = useState(false);
  const shownRef = useRef(false);
  const timeoutRef = useRef(null);

  useEffect(() => () => {
    if (timeoutRef.current !== null) window.clearTimeout(timeoutRef.current);
  }, []);

  const showOnFirstTouch = useCallback((event) => {
    if (event.pointerType !== 'touch' || shownRef.current) return;
    shownRef.current = true;
    setVisible(true);
    timeoutRef.current = window.setTimeout(() => {
      timeoutRef.current = null;
      setVisible(false);
    }, durationMs);
  }, [durationMs]);

  return { visible, showOnFirstTouch };
}