このコミットが含まれているのは:
2025-06-25 02:52:51 +09:00
コミット 6e6ee73857
7個のファイルの変更115行の追加33行の削除
+34 -11
ファイルの表示
@@ -1,45 +1,68 @@
import { useEffect, useState } from 'react'
import { Link, useParams, useNavigate } from 'react-router-dom'
import { Link, useLocation, useParams, useNavigate } from 'react-router-dom'
import ReactMarkdown from 'react-markdown'
import axios from 'axios'
import { API_BASE_URL } from '@/config'
import MainArea from '@/components/layout/MainArea'
import { WikiIdBus } from '@/lib/eventBus/WikiIdBus'
import type { WikiPage } from '@/types'
export default () => {
const { name } = useParams ()
const { title } = useParams ()
const location = useLocation ()
const navigate = useNavigate ()
const [markdown, setMarkdown] = useState<string | null> (null)
const [wikiPage, setWikiPage] = useState<WikiPage | null | undefined> (undefined)
const query = new URLSearchParams (location.search)
const version = query.get ('version')
useEffect (() => {
if (/^\d+$/.test (name))
if (/^\d+$/.test (title))
{
void (axios.get (`${ API_BASE_URL }/wiki/${ name }`)
void (axios.get (`${ API_BASE_URL }/wiki/${ title }`)
.then (res => navigate (`/wiki/${ res.data.title }`, { replace: true })))
return
}
void (axios.get (`${ API_BASE_URL }/wiki/title/${ encodeURIComponent (name) }`)
void (axios.get (`${ API_BASE_URL }/wiki/title/${ encodeURIComponent (title) }`, version && { params: { version } })
.then (res => {
setMarkdown (res.data.body)
setWikiPage (res.data)
WikiIdBus.set (res.data.id)
})
.catch (() => setMarkdown ('')))
}, [name])
.catch (() => setWikiPage (null)))
}, [title, location.search])
return (
<MainArea>
{(wikiPage && version) && (
<div className="text-sm flex gap-3 items-center justify-center border border-gray-700 rounded px-2 py-1 mb-4">
{wikiPage.pred ? (
<Link to={`/wiki/${ title }?version=${ wikiPage.pred }`}
className="text-blue-400 hover:underline">
&lt;
</Link>) : <>&lt; </>}
<span>{wikiPage.updated_at}</span>
{wikiPage.succ ? (
<Link to={`/wiki/${ title }?version=${ wikiPage.succ }`}
className="text-blue-400 hover:underline">
&gt;
</Link>) : <> &gt;</>}
</div>)}
<h1>{title}</h1>
<div className="prose mx-auto p-4">
{markdown == null ? 'Loading...' : (
{wikiPage === undefined ? 'Loading...' : (
<>
<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>)) }}>
{markdown || `このページは存在しません。[新規作成してください](/wiki/new?title=${ name })。`}
{wikiPage?.body || `このページは存在しません。[新規作成してください](/wiki/new?title=${ title })。`}
</ReactMarkdown>
</>)}
</div>
+37
ファイルの表示
@@ -0,0 +1,37 @@
import { useEffect, useState } from 'react'
import { Link, useLocation, useParams } from 'react-router-dom'
import axios from 'axios'
import MainArea from '@/components/layout/MainArea'
import { API_BASE_URL } from '@/config'
import type { WikiPageDiff } from '@/types'
export default () => {
const { id } = useParams ()
const location = useLocation ()
const [diff, setDiff] = useState<WikiPageDiff | null> (null)
const query = new URLSearchParams (location.search)
const from = query.get ('from')
const to = query.get ('to')
useEffect (() => {
void (axios.get (`${ API_BASE_URL }/wiki/${ id }/diff`, { params: { from, to } })
.then (res => setDiff (res.data)))
}, [])
return (
<MainArea>
<h1>{diff?.title}</h1>
<div className="prose mx-auto p-4">
{diff ? (
diff.diff.map (d => (
<span className={d.type === 'added' ? 'bg-green-800' : d.type === 'removed' ? 'bg-red-800' : ''}>
{d.content == '\n' ? <br /> : d.content}
</span>))) : 'Loading...'}
</div>
</MainArea>)
}
+6 -4
ファイルの表示
@@ -33,10 +33,12 @@ export default () => {
<tbody>
{changes.map (change => (
<tr key={change.sha}>
<td>{change.change_type === 'update' && (
<Link>
</Link>)}</td>
<td>
{change.change_type === 'update' && (
<Link to={`/wiki/${ change.wiki_page.id }/diff?from=${ change.pred }&to=${ change.sha }`}>
</Link>)}
</td>
<td className="p-2">
<Link to={`/wiki/${ encodeURIComponent (change.wiki_page.title) }?version=${ change.sha }`}
className="text-blue-400 hover:underline">