|
|
|
@@ -3,12 +3,12 @@ import { match } from 'path-to-regexp' |
|
|
|
|
|
|
|
import { fetchPost, fetchPosts, fetchPostChanges } from '@/lib/posts' |
|
|
|
import { postsKeys, tagsKeys, wikiKeys } from '@/lib/queryKeys' |
|
|
|
import { fetchTagByName } from '@/lib/tags' |
|
|
|
import { fetchTagByName, fetchTags } from '@/lib/tags' |
|
|
|
import { fetchWikiPage, |
|
|
|
fetchWikiPageByTitle, |
|
|
|
fetchWikiPages } from '@/lib/wiki' |
|
|
|
|
|
|
|
import type { FetchPostsOrder } from '@/types' |
|
|
|
import type { Category, FetchPostsOrder, FetchTagsOrder } from '@/types' |
|
|
|
|
|
|
|
type Prefetcher = (qc: QueryClient, url: URL) => Promise<void> |
|
|
|
|
|
|
|
@@ -131,6 +131,32 @@ const prefetchPostChanges: Prefetcher = async (qc, url) => { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const prefetchTagsIndex: Prefetcher = async (qc, url) => { |
|
|
|
const postRaw = url.searchParams.get ('post') |
|
|
|
const post = postRaw ? Number (postRaw) : null |
|
|
|
const name = url.searchParams.get ('name') ?? '' |
|
|
|
const category = (url.searchParams.get ('category') || null) as Category | null |
|
|
|
const postCountGTE = Number (url.searchParams.get ('post_count_gte') || 1) |
|
|
|
const postCountLTERaw = url.searchParams.get ('post_count_lte') |
|
|
|
const postCountLTE = postCountLTERaw ? Number (postCountLTERaw) : null |
|
|
|
const createdFrom = url.searchParams.get ('created_from') ?? '' |
|
|
|
const createdTo = url.searchParams.get ('created_to') ?? '' |
|
|
|
const updatedFrom = url.searchParams.get ('updated_from') ?? '' |
|
|
|
const updatedTo = url.searchParams.get ('updated_to') ?? '' |
|
|
|
const page = Number (url.searchParams.get ('page') || 1) |
|
|
|
const limit = Number (url.searchParams.get ('limit') || 20) |
|
|
|
const order = (url.searchParams.get ('order') ?? 'post_count:desc') as FetchTagsOrder |
|
|
|
|
|
|
|
const keys = { |
|
|
|
post, name, category, postCountGTE, postCountLTE, createdFrom, createdTo, |
|
|
|
updatedFrom, updatedTo, page, limit, order } |
|
|
|
|
|
|
|
await qc.prefetchQuery ({ |
|
|
|
queryKey: tagsKeys.index (keys), |
|
|
|
queryFn: () => fetchTags (keys) }) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const routePrefetchers: { test: (u: URL) => boolean; run: Prefetcher }[] = [ |
|
|
|
{ test: u => ['/', '/posts', '/posts/search'].includes (u.pathname), |
|
|
|
run: prefetchPostsIndex }, |
|
|
|
@@ -141,7 +167,8 @@ 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 }, |
|
|
|
{ test: u => u.pathname === '/tags', run: prefetchTagsIndex }] |
|
|
|
|
|
|
|
|
|
|
|
export const prefetchForURL = async (qc: QueryClient, urlLike: string): Promise<void> => { |
|
|
|
|