Repository navigation
site: extract shared liveData/fetchJson helpers for the live-data components - #438
Merged
Merged
Conversation
…ponents Stats, Activity, and CurrentlyTending each carried their own copy of the fetch / resp.ok-guard / try-catch / hidden=false boilerplate. Lift it into site/src/lib/api.ts: fetchJson<T> (the fetch wrapper, was getJson in CurrentlyTending) and liveData<T>(path, sectionId, render), which fetches, hands the body to render, and reveals the section only if render returns true. WORKER_URL is now module-private. No behavior change. Co-Authored-By: Claude <[email protected]>
tend-agent
approved these changes
May 12, 2026
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
Pure refactor — no behavior change.
Stats.astro,Activity.astro, andCurrentlyTending.astroeach carried their own copy of the same runtime-fetch boilerplate (fetch withAcceptheader,resp.okguard,try/catch → bail,hidden = falseon success). A prior review on #433 flagged the duplication. This lifts it intosite/src/lib/api.ts:fetchJson<T>(path): Promise<T | null>— the fetch wrapper (null on non-OK / network error). WasgetJsoninsideCurrentlyTending.liveData<T>(path, sectionId, render)— looks upgetElementById(sectionId), callsfetchJson(path), hands the parsed body (ornullon failure) torender(data, el), and reveals the element only ifrenderreturnstrue.renderowns the DOM and the "is this worth showing?" decision, and may issue further fetches —CurrentlyTendingpasses anasync renderthat does its/activityfallback this way.WORKER_URLis now module-private toapi.ts(onlyfetchJsonuses it). RenamedCurrentlyTending's localrenderhelper topaintso it doesn't overlap withliveData'srenderparameter. README line updated.Net −12 lines; bundles shrink slightly (a shared
api.*.jschunk replaces the per-component copies).Test plan
npm run buildclean;pre-commit run --all-filesgreen;tsc --noEmitpasses (checked via reviewer)CurrentlyTending's live state (tending owner/repo · review (+2 more)) and idle fallback (last tended N min ago), the stat strip, and the 10-row activity feed — no console errorsCurrentlyTendingstill falls back to/activitywhen/currently-tendingfails (not only when it's empty); each section still hides in exactly the cases it did before