"use client"; import { ChevronRight, Home } from "lucide-react"; import { Fragment, useEffect } from "react"; import { useCatalogManager } from "./use-catalog-store"; export function BreadcrumbBar() { const { state, dispatch } = useCatalogManager(); const { selectedPageId, ancestors } = state; useEffect(() => { if (!selectedPageId || selectedPageId <= 0) { dispatch({ type: "SET_ANCESTORS", ancestors: [] }); return; } const ac = new AbortController(); fetch(`/api/admin/catalog/tree?ancestors=${selectedPageId}`, { signal: ac.signal }) .then((r) => r.json()) .then((d) => { if (!ac.signal.aborted) { dispatch({ type: "SET_ANCESTORS", ancestors: d.ancestors ?? [] }); } }) .catch(() => {}); return () => ac.abort(); }, [selectedPageId, dispatch]); if (!selectedPageId || ancestors.length === 0) return null; return (