mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 06:37:33 +00:00
fix(admin): a failed "Load more" in the desktop release history keeps the list and can be retried
On the desktop admin GitHub panel, when "Load more" failed (for example GitHub rate limiting), the whole release history was replaced by the error card for the rest of the session: no list, no Load more button, no way to retry. Had the user found a way to load again, the next load would also have skipped the page that failed. Cause: in its one page per load mode useGithubReleases advanced the page counter whether the request worked or not and never cleared the error, and GitHubPanel showed the error card whenever an error was set. The phone (fillPages mode) already held the page, cleared the error on the next good load and drew the error inline under its timeline. Fix: the one page mode now moves the page on only after a good load and clears the error then, like fillPages. GitHubPanel shows the error card only when nothing has loaded yet; after that it keeps the timeline, shows the error as a line above Load more and leaves the button there. The page walk difference behind fillPages stays as it was. Red tests: - FE-COMP-GHREL-HOOK-012 (new, useGithubReleases.test.ts) failed with "AssertionError: expected [ 1, 2, 3 ] to deeply equal [ 1, 2, 2 ]". - FE-ADMIN-GH-017 (new, GitHubPanel.test.tsx) failed with "Unable to find an element with the text: /v1\.\d\.0/" after the failed load. Changed assertions in src/components/Admin/useGithubReleases.test.ts: - FE-COMP-GHREL-HOOK-004 (renamed from "sets the error and still moves the page on" to "sets the error and holds the page"): requested pages were [1, 2, 3], now [1, 2, 2].
This commit is contained in:
@@ -23,9 +23,9 @@ interface UseGithubReleasesOptions {
|
||||
isPrerelease: boolean;
|
||||
/**
|
||||
* Keep pulling pages until at least one release survives the prerelease filter, up to
|
||||
* MAX_PAGES_PER_LOAD per load. A failed page then keeps what is already shown and
|
||||
* leaves the page counter where it was, and the next good load clears the error.
|
||||
* Without it each load reads exactly one page and the page counter moves on regardless.
|
||||
* MAX_PAGES_PER_LOAD per load. Without it each load reads exactly one page. Either way
|
||||
* a failed page keeps what is already shown and leaves the page counter where it was,
|
||||
* and the next good load clears the error.
|
||||
*/
|
||||
fillPages?: boolean;
|
||||
}
|
||||
@@ -59,9 +59,11 @@ export function useGithubReleases({ isPrerelease, fillPages = false }: UseGithub
|
||||
|
||||
const fetchReleases = async (pageNum = 1, append = false) => {
|
||||
const data = await fetchPage(pageNum);
|
||||
if (!data) return;
|
||||
if (!data) return false;
|
||||
setReleases((prev) => (append ? [...prev, ...data] : data));
|
||||
setHasMore(data.length === PER_PAGE);
|
||||
setError(null);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Keep pulling pages until at least one release survives the prerelease filter,
|
||||
@@ -102,8 +104,7 @@ export function useGithubReleases({ isPrerelease, fillPages = false }: UseGithub
|
||||
}
|
||||
const next = page + 1;
|
||||
setLoadingMore(true);
|
||||
await fetchReleases(next, true);
|
||||
setPage(next);
|
||||
if (await fetchReleases(next, true)) setPage(next);
|
||||
setLoadingMore(false);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user