| 1 | "use client"; |
| 2 | |
| 3 | import { useCallback, useRef } from "react"; |
| 4 | import { useRouter } from "next/navigation"; |
| 5 | import { useCanopyEvents } from "@/lib/use-canopy-events"; |
| 6 | |
| 7 | interface Props { |
| 8 | scope: "global" | "repo"; |
| 9 | owner?: string; |
| 10 | repo?: string; |
| 11 | } |
| 12 | |
| 13 | export function CanopyLiveRefresh({ scope, owner, repo }: Props) { |
| 14 | const router = useRouter(); |
| 15 | const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null); |
| 16 | |
| 17 | useCanopyEvents({ |
| 18 | scope, |
| 19 | owner, |
| 20 | repo, |
| 21 | onEvent: useCallback(() => { |
| 22 | if (timerRef.current) clearTimeout(timerRef.current); |
| 23 | timerRef.current = setTimeout(() => router.refresh(), 500); |
| 24 | }, [router]), |
| 25 | }); |
| 26 | |
| 27 | return null; |
| 28 | } |
| 29 | |