|
|
@@ -1,12 +1,13 @@ |
|
|
import axios from 'axios' |
|
|
import axios from 'axios' |
|
|
import toCamel from 'camelcase-keys' |
|
|
import toCamel from 'camelcase-keys' |
|
|
import { useEffect, useState } from 'react' |
|
|
|
|
|
|
|
|
import { useEffect, useMemo, useState } from 'react' |
|
|
import ReactMarkdown from 'react-markdown' |
|
|
import ReactMarkdown from 'react-markdown' |
|
|
import { Link } from 'react-router-dom' |
|
|
import { Link } from 'react-router-dom' |
|
|
|
|
|
|
|
|
import SectionTitle from '@/components/common/SectionTitle' |
|
|
import SectionTitle from '@/components/common/SectionTitle' |
|
|
import SubsectionTitle from '@/components/common/SubsectionTitle' |
|
|
import SubsectionTitle from '@/components/common/SubsectionTitle' |
|
|
import { API_BASE_URL } from '@/config' |
|
|
import { API_BASE_URL } from '@/config' |
|
|
|
|
|
import remarkWikiAutoLink from '@/lib/remark-wiki-autolink' |
|
|
|
|
|
|
|
|
import type { Components } from 'react-markdown' |
|
|
import type { Components } from 'react-markdown' |
|
|
|
|
|
|
|
|
@@ -34,6 +35,8 @@ export default ({ title, body }: Props) => { |
|
|
const [pageNames, setPageNames] = useState<string[]> ([]) |
|
|
const [pageNames, setPageNames] = useState<string[]> ([]) |
|
|
const [realBody, setRealBody] = useState<string> ('') |
|
|
const [realBody, setRealBody] = useState<string> ('') |
|
|
|
|
|
|
|
|
|
|
|
const remarkPlugins = useMemo (() => [remarkWikiAutoLink (pageNames)], [pageNames]) |
|
|
|
|
|
|
|
|
useEffect (() => { |
|
|
useEffect (() => { |
|
|
if (!(body)) |
|
|
if (!(body)) |
|
|
return |
|
|
return |
|
|
@@ -42,7 +45,7 @@ export default ({ title, body }: Props) => { |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
const res = await axios.get (`${ API_BASE_URL }/wiki`) |
|
|
const res = await axios.get (`${ API_BASE_URL }/wiki`) |
|
|
const data = toCamel (res.data as any, { deep: true }) as WikiPage[] |
|
|
|
|
|
|
|
|
const data: WikiPage[] = toCamel (res.data as any, { deep: true }) |
|
|
setPageNames (data.map (page => page.title).sort ((a, b) => b.length - a.length)) |
|
|
setPageNames (data.map (page => page.title).sort ((a, b) => b.length - a.length)) |
|
|
} |
|
|
} |
|
|
catch |
|
|
catch |
|
|
@@ -50,9 +53,7 @@ export default ({ title, body }: Props) => { |
|
|
setPageNames ([]) |
|
|
setPageNames ([]) |
|
|
} |
|
|
} |
|
|
}) () |
|
|
}) () |
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
useEffect (() => { |
|
|
|
|
|
setRealBody ('') |
|
|
setRealBody ('') |
|
|
}, [body]) |
|
|
}, [body]) |
|
|
|
|
|
|
|
|
@@ -97,7 +98,7 @@ export default ({ title, body }: Props) => { |
|
|
}, [body, pageNames]) |
|
|
}, [body, pageNames]) |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<ReactMarkdown components={mdComponents}> |
|
|
|
|
|
|
|
|
<ReactMarkdown components={mdComponents} remarkPlugins={remarkPlugins}> |
|
|
{realBody || `このページは存在しません。[新規作成してください](/wiki/new?title=${ encodeURIComponent (title) })。`} |
|
|
{realBody || `このページは存在しません。[新規作成してください](/wiki/new?title=${ encodeURIComponent (title) })。`} |
|
|
</ReactMarkdown>) |
|
|
</ReactMarkdown>) |
|
|
} |
|
|
} |