/** * Hook for fetching lore status data via Tauri IPC. * * Uses TanStack Query for caching and state management. * The data can be refreshed via query invalidation when * lore-data-changed events are received. */ import { useQuery } from "@tanstack/react-query"; import { getLoreStatus } from "@/lib/tauri"; import type { LoreStatus } from "@/lib/bindings"; export interface UseLoreDataResult { data: LoreStatus | undefined; isLoading: boolean; error: Error | null; refetch: () => void; } /** * Fetch lore status data from the Tauri backend. * * Returns the current lore status including health, last sync time, * and summary counts (open issues, authored MRs, reviewing MRs). */ export function useLoreData(): UseLoreDataResult { const query = useQuery({ queryKey: ["lore-status"], queryFn: async (): Promise => { const result = await getLoreStatus(); if (result.status === "error") { throw new Error(result.error.message); } return result.data; }, refetchInterval: false, // Manual refetch on lore-data-changed staleTime: 30_000, // Consider data fresh for 30 seconds }); return { data: query.data, isLoading: query.isLoading, error: query.error, refetch: query.refetch, }; }