'use client' import { useCallback, useEffect, useState } from 'react' import Link from 'next/link' import { parseGitStatus } from '@/lib/parse-git' import { fetchAgentOutput } from '@/lib/agent-fetch' type GitData = { dirty: number; total: number } export type GitInitial = | { configured: false } | { data: GitData; error: null } | { data: null; error: string } async function refreshGit(repos: string[]): Promise { const results = await Promise.allSettled( repos.map(async (path) => { const output = await fetchAgentOutput('git_status', [path]) return parseGitStatus(output) }), ) const dirty = results.filter( (r) => r.status === 'fulfilled' && r.value.dirty, ).length return { dirty, total: repos.length } } export default function GitWidget({ initial, repos }: { initial: GitInitial; repos: string[] }) { const notConfigured = 'configured' in initial && initial.configured === false const [data, setData] = useState( !notConfigured && 'data' in initial ? initial.data : null, ) const [error, setError] = useState( !notConfigured && 'error' in initial ? initial.error : null, ) const refresh = useCallback(async () => { if (notConfigured || repos.length === 0) return try { const d = await refreshGit(repos) setData(d) setError(null) } catch (err) { setError(err instanceof Error ? err.message : 'refresh failed') } }, [notConfigured, repos]) useEffect(() => { if (notConfigured) return const id = setInterval(refresh, 30_000) return () => clearInterval(id) }, [refresh, notConfigured]) return (

Git

{notConfigured ? (

niet geconfigureerd

) : error ? (

{error}

) : data ? (

{data.dirty} {' '}repo{data.dirty !== 1 ? 's' : ''} dirty

) : (

)} ) }