Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

872 B
Raw Blame
import { useEffect, useRef } from "react";
import { sectionPrefetch } from "@/lib/sectionPrefetch";
import type { SectionId } from "@/store/events";

export const SECTION_PREFETCH_DELAY_MS = 150;

/** A brief hover/focus warms one destination; passing over the rail warms none. */
export function useSectionPrefetch(section: SectionId) {
  const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
  const cancel = () => {
    if (timer.current !== null) clearTimeout(timer.current);
    timer.current = null;
  };
  useEffect(() => cancel, [section]);

  const schedule = () => {
    cancel();
    timer.current = setTimeout(() => {
      timer.current = null;
      void sectionPrefetch.prefetch(section);
    }, SECTION_PREFETCH_DELAY_MS);
  };

  return {
    onMouseEnter: schedule,
    onMouseLeave: cancel,
    onFocus: schedule,
    onBlur: cancel,
  };
}