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