Browse Source

#140

pull/254/head
みてるぞ 5 days ago
parent
commit
26bd40d804
3 changed files with 16 additions and 6 deletions
  1. +1
    -1
      frontend/src/components/TopNav.tsx
  2. +14
    -4
      frontend/src/lib/prefetchers.ts
  3. +1
    -1
      frontend/src/lib/wiki.ts

+ 1
- 1
frontend/src/components/TopNav.tsx View File

@@ -65,7 +65,7 @@ export default (({ user }: Props) => {
const postCount = tag?.postCount ?? 0

const wikiPageFlg = Boolean (/^\/wiki\/(?!new|changes)[^\/]+/.test (location.pathname) && wikiId)
const wikiTitle = location.pathname.split ('/')[2]
const wikiTitle = location.pathname.split ('/')[2] ?? ''
const menu: Menu = [
{ name: '広場', to: '/posts', subMenu: [
{ name: '一覧', to: '/posts' },


+ 14
- 4
frontend/src/lib/prefetchers.ts View File

@@ -4,7 +4,9 @@ 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 { fetchWikiPageByTitle, fetchWikiPages } from '@/lib/wiki'
import { fetchWikiPage,
fetchWikiPageByTitle,
fetchWikiPages } from '@/lib/wiki'

type Prefetcher = (qc: QueryClient, url: URL) => Promise<void>

@@ -33,11 +35,19 @@ const prefetchWikiPageShow: Prefetcher = async (qc, url) => {
queryKey: wikiKeys.show (title, { version }),
queryFn: () => fetchWikiPageByTitle (title, { version }) })

if (wikiPage?.body)
if (wikiPage)
{
const effectiveId = String (wikiPage.id ?? '')
await qc.prefetchQuery ({
queryKey: wikiKeys.index ({ }),
queryFn: () => fetchWikiPages ({ }) })
queryKey: wikiKeys.show (effectiveId, { }),
queryFn: () => fetchWikiPage (effectiveId, { } ) })

if (wikiPage.body)
{
await qc.prefetchQuery ({
queryKey: wikiKeys.index ({ }),
queryFn: () => fetchWikiPages ({ }) })
}
}

const effectiveTitle = wikiPage?.title ?? title


+ 1
- 1
frontend/src/lib/wiki.ts View File

@@ -22,7 +22,7 @@ export const fetchWikiPageByTitle = async (
): Promise<WikiPage | null> => {
try
{
return await apiGet (`/wiki/title/${ title }`, { params: { version } })
return await apiGet (`/wiki/title/${ encodeURIComponent (title) }`, { params: { version } })
}
catch
{


Loading…
Cancel
Save