|
|
|
@@ -31,13 +31,31 @@ const prefetchWikiPageShow: Prefetcher = async (qc, url) => { |
|
|
|
|
|
|
|
const wikiPage = await qc.fetchQuery ({ |
|
|
|
queryKey: wikiKeys.show (title, { version }), |
|
|
|
queryFn: () => fetchWikiPageByTitle (title, { version }) }) |
|
|
|
|
|
|
|
const effectiveTitle = wikiPage.title |
|
|
|
queryFn: async () => { |
|
|
|
try |
|
|
|
{ |
|
|
|
return await fetchWikiPageByTitle (title, { version }) |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
return null |
|
|
|
} |
|
|
|
} }) |
|
|
|
|
|
|
|
const effectiveTitle = wikiPage?.title ?? title |
|
|
|
|
|
|
|
await qc.prefetchQuery ({ |
|
|
|
queryKey: tagsKeys.show (effectiveTitle), |
|
|
|
queryFn: () => fetchTagByName (effectiveTitle) }) |
|
|
|
queryFn: async () => { |
|
|
|
try |
|
|
|
{ |
|
|
|
return await fetchTagByName (effectiveTitle) |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
return null |
|
|
|
} |
|
|
|
} }) |
|
|
|
|
|
|
|
if (version) |
|
|
|
return |
|
|
|
@@ -85,7 +103,7 @@ const prefetchPostChanges: Prefetcher = async (qc, url) => { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const routePrefetchers: { test: (u: URL) => boolean; run: Prefetcher }[] = [ |
|
|
|
export const routePrefetchers: { test: (u: URL) => boolean; run: Prefetcher }[] = [ |
|
|
|
{ test: u => u.pathname === '/' || u.pathname === '/posts', run: prefetchPostsIndex }, |
|
|
|
{ test: u => (!(['/posts/new', '/posts/changes'].includes (u.pathname)) |
|
|
|
&& Boolean (mPost (u.pathname))), |
|
|
|
@@ -94,15 +112,13 @@ export const routePrefetchers: { test: (u: URL) => boolean; run: Prefetcher }[] |
|
|
|
{ test: u => u.pathname === '/wiki', run: prefetchWikiPagesIndex }, |
|
|
|
{ test: u => (!(['/wiki/new', '/wiki/changes'].includes (u.pathname)) |
|
|
|
&& Boolean (mWiki (u.pathname))), |
|
|
|
run: prefetchWikiPageShow }, |
|
|
|
] |
|
|
|
run: prefetchWikiPageShow }] |
|
|
|
|
|
|
|
|
|
|
|
export const prefetchForURL = async (qc: QueryClient, urlLike: string): Promise<void> => { |
|
|
|
const u = new URL (urlLike, location.origin) |
|
|
|
const jobs = routePrefetchers.filter (r => r.test (u)).map (r => r.run (qc, u)) |
|
|
|
if (jobs.length === 0) |
|
|
|
const r = routePrefetchers.find (x => x.test (u)) |
|
|
|
if (!(r)) |
|
|
|
return |
|
|
|
|
|
|
|
await Promise.all (jobs) |
|
|
|
await r.run (qc, u) |
|
|
|
} |