Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

721 B
Raw Blame
import { useEffect, useRef } from "react";
import { useRouter, useSearchParams } from "next/navigation";

// Armed by the Match button on the jobs list. The flag is dropped on the first
// run so the router.refresh() the chat fires after saving the match — or any
// other re-render — cannot start a second one.
export function useAutoMatch(onMatch: () => void) {
  const router = useRouter();
  const searchParams = useSearchParams();
  const armed = searchParams.get("match") === "1";
  const firedRef = useRef(false);

  useEffect(() => {
    if (!armed || firedRef.current) return;
    firedRef.current = true;
    router.replace("?tab=match", { scroll: false });
    onMatch();
  }, [armed, onMatch, router]);
}