みてるぞ 1 week ago
parent
commit
cc6d50cf17
3 changed files with 23 additions and 7 deletions
  1. +19
    -4
      frontend/src/components/WikiBody.tsx
  2. +1
    -1
      frontend/src/pages/posts/PostListPage.tsx
  3. +3
    -2
      frontend/src/pages/wiki/WikiDetailPage.tsx

+ 19
- 4
frontend/src/components/WikiBody.tsx View File

@@ -4,13 +4,31 @@ import { useEffect, useState } from 'react'
import ReactMarkdown from 'react-markdown'
import { Link } from 'react-router-dom'

import SectionTitle from '@/components/common/SectionTitle'
import SubsectionTitle from '@/components/common/SubsectionTitle'
import { API_BASE_URL } from '@/config'

import type { Components } from 'react-markdown'

import type { WikiPage } from '@/types'

type Props = { title: string
body?: string }

const mdComponents = { h1: ({ children }) => <SectionTitle>{children}</SectionTitle>,
h2: ({ children }) => <SubsectionTitle>{children}</SubsectionTitle>,
ol: ({ children }) => <ol className="list-decimal pl-6">{children}</ol>,
ul: ({ children }) => <ul className="list-disc pl-6">{children}</ul>,
a: (({ href, children }) => (
['/', '.'].some (e => href?.startsWith (e))
? <Link to={href!}>{children}</Link>
: (
<a href={href}
target="_blank"
rel="noopener noreferrer">
{children}
</a>))) } as const satisfies Components


export default ({ title, body }: Props) => {
const [pageNames, setPageNames] = useState<string[]> ([])
@@ -75,10 +93,7 @@ export default ({ title, body }: Props) => {
}, [pageNames])

return (
<ReactMarkdown components={{ a: (
({ href, children }) => (['/', '.'].some (e => href?.startsWith (e))
? <Link to={href!}>{children}</Link>
: <a href={href} target="_blank" rel="noopener noreferrer">{children}</a>)) }}>
<ReactMarkdown components={mdComponents}>
{realBody || `このページは存在しません。[新規作成してください](/wiki/new?title=${ encodeURIComponent (title) })。`}
</ReactMarkdown>)
}

+ 1
- 1
frontend/src/pages/posts/PostListPage.tsx View File

@@ -131,7 +131,7 @@ export default () => {
</Tab>
{tags.length === 1 && (
<Tab name="Wiki">
<WikiBody body={wikiPage?.body} title={tags[0]} />
<WikiBody title={tags[0]} body={wikiPage?.body} />
<div className="my-2">
<Link to={`/wiki/${ encodeURIComponent (tags[0]) }`}>
Wiki を見る


+ 3
- 2
frontend/src/pages/wiki/WikiDetailPage.tsx View File

@@ -60,6 +60,7 @@ export default () => {
}
}) ()

setPosts ([])
void (async () => {
try
{
@@ -73,7 +74,7 @@ export default () => {
}
catch
{
setPosts ([])
;
}
}) ()

@@ -123,7 +124,7 @@ export default () => {
<div className="prose mx-auto p-4">
{wikiPage === undefined
? 'Loading...'
: <WikiBody body={wikiPage?.body} title={title} />}
: <WikiBody title={title} body={wikiPage?.body} />}
</div>

{(!(version) && posts.length > 0) && (


Loading…
Cancel
Save