refactor(lib): add usePolling hook for stats and admin#228
Open
pq198363-ops wants to merge 2 commits into
Open
refactor(lib): add usePolling hook for stats and admin#228pq198363-ops wants to merge 2 commits into
pq198363-ops wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
usePolling<T>hook that uses the sharedapiGetclient, fetches immediately, polls on an interval, supports pause/resume/manual refresh, trackslastUpdated, and aborts superseded or unmounted requests.usePolling<Stats>("/api/v1/stats", 5000)instead of a localsetIntervalloop./api/v1/admin/status, while still awaiting an immediate refresh after pause/unpause actions.docs/hooks.mdandREADME.md.Breadcrumb,formatRequests, andsafeHrefso 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 --runInBandnpx 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='{}' --runInBandsrc/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.tsxnpx tsc --noEmit --pretty false --skipLibCheck --lib dom,dom.iterable,esnext src/lib/usePolling.tsgit diff --cached --checknpm run typechecknpm run lintsrc/app/webhooks/page.tsxfor unusedEmptyStateandSpinnerimports.npm run buildnpm test -- --runInBandNotes
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.