You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
958 B
TypeScript

// frontend/lib/hooks/useConnectors.ts — SWR 커넥터 상태 목록
"use client";
import useSWR from "swr";
import type { ConnectorStatus } from "@/lib/types";
import { connectorsApi } from "@/lib/connectors/api";
export function useConnectors(domain = "") {
const { data, error, isLoading, mutate } = useSWR<ConnectorStatus[]>(
domain ? `/api/connectors?domain=${domain}` : "/api/connectors",
() => connectorsApi.list(domain),
{
revalidateOnFocus: false,
// 초기 연결 직후엔 백그라운드 sync 가 도는 동안 state="syncing" 이다.
// 동기화 중인 계정이 하나라도 있으면 끝날 때까지 2초마다 갱신, 끝나면 멈춘다.
// (이게 없으면 "동기화 중…" 카드가 완료된 뒤에도 안 바뀌고 멈춰 있음.)
refreshInterval: (latest) => (latest?.some((c) => c.state === "syncing") ? 2000 : 0),
},
);
return { data, isLoading, error, refresh: mutate };
}