Skip to content

refactor(lib): add usePolling hook for stats and admin#228

Open
pq198363-ops wants to merge 2 commits into
Agentpay-Org:mainfrom
pq198363-ops:bounty-73-use-polling-hook
Open

refactor(lib): add usePolling hook for stats and admin#228
pq198363-ops wants to merge 2 commits into
Agentpay-Org:mainfrom
pq198363-ops:bounty-73-use-polling-hook

Conversation

@pq198363-ops

@pq198363-ops pq198363-ops commented Jul 4, 2026

Copy link
Copy Markdown

Summary

  • Add a reusable usePolling<T> hook that uses the shared apiGet client, fetches immediately, polls on an interval, supports pause/resume/manual refresh, tracks lastUpdated, and aborts superseded or unmounted requests.
  • Refactor the stats page to use usePolling<Stats>("/api/v1/stats", 5000) instead of a local setInterval loop.
  • Refactor the admin status panel to use the same hook for /api/v1/admin/status, while still awaiting an immediate refresh after pause/unpause actions.
  • Document the hook contract and current adopters in docs/hooks.md and README.md.
  • Restore existing missing imports for Breadcrumb, formatRequests, and safeHref so the repository build/test pipeline can complete on this PR.

Closes #73

Validation

  • npx jest src/lib/__tests__/usePolling.test.tsx src/app/stats/page.test.tsx src/app/admin/page.test.tsx src/app/admin/__tests__/admin-page-stale-guard.test.tsx --runInBand
    • 4 suites passed; 23 tests passed; 2 skipped existing skipped tests.
  • npx jest src/lib/__tests__/usePolling.test.tsx src/app/stats/page.test.tsx src/app/admin/page.test.tsx src/app/admin/__tests__/admin-page-stale-guard.test.tsx --coverage --collectCoverageFrom=src/lib/usePolling.ts --collectCoverageFrom=src/app/stats/page.tsx --collectCoverageFrom=src/app/admin/page.tsx --coverageReporters=text --coverageThreshold='{}' --runInBand
    • src/lib/usePolling.ts: 100% statements, 100% branches, 100% functions, 100% lines.
    • src/app/stats/page.tsx: 100% statements, 100% branches, 100% functions, 100% lines.
    • src/app/admin/page.tsx: 100% statements, 97.82% branches, 100% functions, 100% lines.
  • npx eslint src/lib/usePolling.ts src/lib/__tests__/usePolling.test.tsx src/app/stats/page.tsx src/app/stats/page.test.tsx src/app/admin/page.tsx src/app/admin/page.test.tsx src/app/admin/__tests__/admin-page-stale-guard.test.tsx
  • npx tsc --noEmit --pretty false --skipLibCheck --lib dom,dom.iterable,esnext src/lib/usePolling.ts
  • git diff --cached --check
  • npm run typecheck
  • npm run lint
    • Passes with existing warnings only in src/app/webhooks/page.tsx for unused EmptyState and Spinner imports.
  • npm run build
  • npm test -- --runInBand
    • 62 suites passed; 606 tests passed; 2 skipped.

Notes

The second commit only restores imports for existing symbols that were already referenced on main; it is included here because the PR build runs the full frontend pipeline before reaching the focused hook tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a reusable usePolling hook and adopt it in the stats and admin pages

1 participant