diff --git a/src/components/GitHubActionsFetcher.tsx b/src/components/GitHubActionsFetcher.tsx index 08612e16d..cab1c2043 100644 --- a/src/components/GitHubActionsFetcher.tsx +++ b/src/components/GitHubActionsFetcher.tsx @@ -26,6 +26,8 @@ export function GitHubActionsFetcher() { const [error, setError] = useState(null) const [lastFetched, setLastFetched] = useState(null) const [needsAuth, setNeedsAuth] = useState(false) + const [secondsUntilRefresh, setSecondsUntilRefresh] = useState(30) + const [autoRefreshEnabled, setAutoRefreshEnabled] = useState(true) const fetchGitHubActions = async () => { setIsLoading(true) @@ -50,6 +52,7 @@ export function GitHubActionsFetcher() { setData(workflows.workflow_runs as WorkflowRun[]) setLastFetched(new Date()) + setSecondsUntilRefresh(30) toast.success(`Fetched ${workflows.workflow_runs.length} workflow runs`) } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred' @@ -64,6 +67,22 @@ export function GitHubActionsFetcher() { fetchGitHubActions() }, []) + useEffect(() => { + if (!autoRefreshEnabled) return + + const countdownInterval = setInterval(() => { + setSecondsUntilRefresh((prev) => { + if (prev <= 1) { + fetchGitHubActions() + return 30 + } + return prev - 1 + }) + }, 1000) + + return () => clearInterval(countdownInterval) + }, [autoRefreshEnabled]) + const getStatusColor = (status: string, conclusion: string | null) => { if (status === 'completed') { if (conclusion === 'success') return 'text-green-600' @@ -131,14 +150,35 @@ export function GitHubActionsFetcher() { Repository: johndoe6345789/metabuilder

- +
+
+
+ + Auto-refresh {autoRefreshEnabled ? 'ON' : 'OFF'} + + {autoRefreshEnabled && ( + + Next refresh: {secondsUntilRefresh}s + + )} +
+ +
+ +
{conclusion && (