/** * The account gate every screen waits on. * * The last visit's account and repository rows are read synchronously from * this origin's storage, so a route's loader can ask the server for a * repository on the first frame. The fresh answer then corrects the rows in * place. A first visit has nothing to read, and waits for discovery. */ import { primeAuthors } from './authors.js'; import { discover, loadRepos, primeFromCache, reposKey } from './git.js'; /** @type {ReturnType|undefined} */ let primed; /** * Prime once per page load, and answer the same way after. * @returns {ReturnType} */ export function primeOnce() { if (primed === undefined) { primeAuthors(); primed = primeFromCache(); } return primed; } /** * Discovery names the account and its PDS, and the repository list has to be * in hand before any screen renders: every route below the list reads its * refs out of that record. * @param {import('@tanstack/react-query').QueryClient} queryClient */ export async function loadAccount(queryClient) { const found = await discover(); const repos = await loadRepos(); // The list screen may be showing the previous visit's rows; this hands it // the fresh ones in place. queryClient.setQueryData([reposKey()], repos); return found; }