This commit is contained in:
2025-06-13 01:36:53 +09:00
parent 3363fcd2ae
commit 32ed235807
11 changed files with 327 additions and 259 deletions
+10 -21
View File
@@ -3,6 +3,7 @@ import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-d
import TagPage from '@/pages/TagPage' import TagPage from '@/pages/TagPage'
import TopNav from '@/components/TopNav' import TopNav from '@/components/TopNav'
import TagSidebar from '@/components/TagSidebar' import TagSidebar from '@/components/TagSidebar'
import TagDetailSidebar from '@/components/TagDetailSidebar'
import PostPage from '@/pages/PostPage' import PostPage from '@/pages/PostPage'
import PostNewPage from '@/pages/PostNewPage' import PostNewPage from '@/pages/PostNewPage'
import PostDetailPage from '@/pages/PostDetailPage' import PostDetailPage from '@/pages/PostDetailPage'
@@ -16,15 +17,13 @@ import { camelizeKeys } from 'humps'
import type { Post, Tag, User } from '@/types' import type { Post, Tag, User } from '@/types'
const App = () => { export default () => {
const [posts, setPosts] = useState<Post[]> ([])
const [user, setUser] = useState<User | null> (null) const [user, setUser] = useState<User | null> (null)
useEffect (() => { useEffect (() => {
const createUser = () => ( const createUser = () => (
axios.post (`${ API_BASE_URL }/users`) axios.post (`${ API_BASE_URL }/users`)
.then (res => { .then (res => {
if (res.data.code) if (res.data.code)
{ {
localStorage.setItem ('user_code', res.data.code) localStorage.setItem ('user_code', res.data.code)
@@ -56,28 +55,18 @@ const App = () => {
<TopNav user={user} setUser={setUser} /> <TopNav user={user} setUser={setUser} />
<div className="flex flex-1"> <div className="flex flex-1">
<Routes> <Routes>
<Route path="/posts/new" /> <Route path="/" element={<Navigate to="/posts" replace />} />
<Route path="/posts" element={<TagSidebar posts={posts} setPosts={setPosts} />} /> <Route path="/posts" element={<PostPage />} />
<Route path="/posts/:id" element={<TagSidebar posts={posts} setPosts={setPosts} />} /> <Route path="/posts/new" element={<PostNewPage />} />
<Route path="/posts/:id" element={<PostDetailPage />} />
<Route path="/tags/:tag" element={<TagPage />} />
<Route path="/wiki/:name" element={<WikiDetailPage />} />
<Route path="/wiki/new" element={<WikiNewPage />} />
{/* <Route path="/wiki/:id/edit" element={<WikiEditPage />} /> */}
</Routes> </Routes>
<main className="flex-1 overflow-y-auto p-4">
<Routes>
<Route path="/" element={<Navigate to="/posts" replace />} />
<Route path="/posts" element={<PostPage posts={posts} setPosts={setPosts} />} />
<Route path="/posts/new" element={<PostNewPage />} />
<Route path="/posts/:id" element={<PostDetailPage posts={posts} setPosts={setPosts} />} />
<Route path="/tags/:tag" element={<TagPage />} />
<Route path="/wiki/:name" element={<WikiDetailPage />} />
<Route path="/wiki/new" element={<WikiNewPage />} />
{/* <Route path="/wiki/:id/edit" element={<WikiEditPage />} /> */}
</Routes>
</main>
</div> </div>
</div> </div>
</Router> </Router>
<Toaster /> <Toaster />
</>) </>)
} }
export default App
@@ -0,0 +1,60 @@
import React, { useEffect, useState } from 'react'
import axios from 'axios'
import { Link, useParams } from 'react-router-dom'
import { API_BASE_URL } from '@/config'
import TagSearch from './TagSearch'
import SidebarComponent from './layout/SidebarComponent'
import type { Post, Tag } from '@/types'
type TagByCategory = { [key: string]: Tag[] }
type Props = { post: Post | null }
export default ({ post }: Props) => {
const [tags, setTags] = useState<TagByCategory> ({ })
const categoryNames: { [key: string]: string } = {
general: '一般',
deerjikist: 'ニジラー',
nico: 'ニコニコタグ' }
useEffect (() => {
if (!(post))
return
const fetchTags = async () => {
const tagsTmp: TagByCategory = { }
for (const tag of post.tags)
{
if (!(tag.category in tagsTmp))
tagsTmp[tag.category] = []
tagsTmp[tag.category].push (tag)
}
for (const cat of Object.keys (tagsTmp))
tagsTmp[cat].sort ((tagA, tagB) => tagA.name < tagB.name ? -1 : 1)
setTags (tagsTmp)
}
fetchTags ()
}, [post])
return (
<SidebarComponent>
<TagSearch />
{['general', 'deerjikist', 'nico'].map (cat => cat in tags && (
<>
<h2>{categoryNames[cat]}</h2>
<ul>
{tags[cat].map (tag => (
<li key={tag.id} className="mb-2">
<Link to={`/posts?${ (new URLSearchParams ({ tags: tag.name })).toString () }`}
className="text-blue-600 hover:underline">
{tag.name}
</Link>
</li>))}
</ul>
</>))}
</SidebarComponent>)
}
+23 -36
View File
@@ -1,15 +1,15 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import axios from 'axios' import axios from 'axios'
import { Link, useParams } from 'react-router-dom' import { Link, useParams } from 'react-router-dom'
import { API_BASE_URL } from '../config' import { API_BASE_URL } from '@/config'
import TagSearch from './TagSearch' import TagSearch from './TagSearch'
import SidebarComponent from './layout/SidebarComponent'
import type { Post, Tag } from '@/types' import type { Post, Tag } from '@/types'
type TagByCategory = { [key: string]: Tag[] } type TagByCategory = { [key: string]: Tag[] }
type Props = { posts: Post[] type Props = { posts: Post[] }
setPosts: (posts: Post[]) => void }
const tagNameMap: { [key: string]: string } = { const tagNameMap: { [key: string]: string } = {
@@ -17,46 +17,35 @@ const tagNameMap: { [key: string]: string } = {
deerjikist: 'ニジラー', deerjikist: 'ニジラー',
nico: 'ニコニコタグ' } nico: 'ニコニコタグ' }
const TagSidebar: React.FC = (props: Props) => {
const { posts, setPosts } = props
export default ({ posts }: Props) => {
const [tags, setTags] = useState<TagByCategory> ({ }) const [tags, setTags] = useState<TagByCategory> ({ })
const [tagsCounts, setTagsCounts] = useState<{ [key: id]: number }> ({ }) const [tagsCounts, setTagsCounts] = useState<{ [key: number]: number }> ({ })
useEffect (() => { useEffect (() => {
const fetchTags = async () => { const tagsTmp: TagByCategory = { }
try const tagsCountsTmp: { [key: number]: number } = { }
for (const post of posts)
{ {
let tagsTmp: TagByCategory = { } for (const tag of post.tags)
let tagsCountsTmp: { [key: id]: number } = { }
for (const post of posts)
{ {
for (const tag of post.tags) if (!(tag.category in tagsTmp))
{ tagsTmp[tag.category] = []
if (!(tag.category in tagsTmp)) if (!(tagsTmp[tag.category].map (t => t.id).includes (tag.id)))
tagsTmp[tag.category] = [] tagsTmp[tag.category].push (tag)
tagsTmp[tag.category].push (tag) if (!(tag.id in tagsCountsTmp))
if (!(tag.id in tagsCountsTmp)) tagsCountsTmp[tag.id] = 0
tagsCountsTmp[tag.id] = 0 ++tagsCountsTmp[tag.id]
++tagsCountsTmp[tag.id]
}
} }
for (const cat of Object.keys (tagsTmp))
tagsTmp[cat].sort ((tagA, tagB) => tagA.name < tagB.name ? -1 : 1)
setTags (tagsTmp)
setTagsCounts (tagsCountsTmp)
} }
catch (error) for (const cat of Object.keys (tagsTmp))
{ tagsTmp[cat].sort ((tagA, tagB) => tagA.name < tagB.name ? -1 : 1)
console.error ('Failed to fetch tags:', error) setTags (tagsTmp)
} setTagsCounts (tagsCountsTmp)
}
fetchTags ()
}, [posts]) }, [posts])
return ( return (
<div className="w-64 bg-gray-100 p-4 border-r border-gray-200 h-full"> <SidebarComponent>
<TagSearch /> <TagSearch />
{['general', 'deerjikist', 'nico'].map (cat => cat in tags && <> {['general', 'deerjikist', 'nico'].map (cat => cat in tags && <>
<h2>{tagNameMap[cat]}</h2> <h2>{tagNameMap[cat]}</h2>
@@ -67,11 +56,9 @@ const TagSidebar: React.FC = (props: Props) => {
className="text-blue-600 hover:underline"> className="text-blue-600 hover:underline">
{tag.name} {tag.name}
</Link> </Link>
{posts.length > 1 && <span className="ml-1">{tagsCounts[tag.id]}</span>} <span className="ml-1">{tagsCounts[tag.id]}</span>
</li>))} </li>))}
</ul> </ul>
</>)} </>)}
</div>) </SidebarComponent>)
} }
export default TagSidebar
@@ -0,0 +1,9 @@
import React from 'react'
type Props = { children: React.ReactNode }
export default ({ children }: Props) => (
<main className="flex-1 overflow-y-auto p-4">
{children}
</main>)
@@ -0,0 +1,9 @@
import React from 'react'
type Props = { children: React.ReactNode }
export default ({ children }: Props) => (
<div className="w-64 bg-gray-100 p-4 border-r border-gray-200 h-full">
{children}
</div>)
+50 -38
View File
@@ -1,32 +1,33 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { Link, useLocation, useParams } from 'react-router-dom' import { Link, useLocation, useParams } from 'react-router-dom'
import axios from 'axios' import axios from 'axios'
import { API_BASE_URL, SITE_TITLE } from '../config' import { API_BASE_URL, SITE_TITLE } from '@/config'
import NicoViewer from '../components/NicoViewer' import NicoViewer from '@/components/NicoViewer'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import { toast } from '@/components/ui/use-toast' import { toast } from '@/components/ui/use-toast'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import MainArea from '@/components/layout/MainArea'
import TagDetailSidebar from '@/components/TagDetailSidebar'
import type { Post, Tag } from '@/types' import type { Post, Tag } from '@/types'
type Props = { posts: Post[]
setPosts: (posts: Post[]) => void }
const PostDetailPage = () => {
const PostDetailPage = ({ posts, setPosts }: Props) => {
const { id } = useParams () const { id } = useParams ()
const [post, setPost] = useState<Post | null> (null)
const location = useLocation () const location = useLocation ()
const changeViewedFlg = () => { const changeViewedFlg = () => {
if (posts[0]?.viewed) if (post?.viewed)
{ {
void (axios.delete ( void (axios.delete (
`${ API_BASE_URL }/posts/${ id }/viewed`, `${ API_BASE_URL }/posts/${ id }/viewed`,
{ headers: { 'X-Transfer-Code': localStorage.getItem ('user_code') || '' } }) { headers: { 'X-Transfer-Code': localStorage.getItem ('user_code') || '' } })
.then (res => setPosts (([post]) => { .then (res => setPost (post => {
post.viewed = false post.viewed = false
return [post] return post
})) }))
.catch (err => toast ({ title: '失敗……', .catch (err => toast ({ title: '失敗……',
description: '通信に失敗しました……' }))) description: '通信に失敗しました……' })))
@@ -37,9 +38,9 @@ const PostDetailPage = ({ posts, setPosts }: Props) => {
`${ API_BASE_URL }/posts/${ id }/viewed`, `${ API_BASE_URL }/posts/${ id }/viewed`,
{ }, { },
{ headers: { 'X-Transfer-Code': localStorage.getItem ('user_code') || '' } }) { headers: { 'X-Transfer-Code': localStorage.getItem ('user_code') || '' } })
.then (res => setPosts (([post]) => { .then (res => setPost (post => {
post.viewed = true post.viewed = true
return [post] return post
})) }))
.catch (err => toast ({ title: '失敗……', .catch (err => toast ({ title: '失敗……',
description: '通信に失敗しました……' }))) description: '通信に失敗しました……' })))
@@ -51,40 +52,51 @@ const PostDetailPage = ({ posts, setPosts }: Props) => {
return return
void (axios.get (`${ API_BASE_URL }/posts/${ id }`, { headers: { void (axios.get (`${ API_BASE_URL }/posts/${ id }`, { headers: {
'X-Transfer-Code': localStorage.getItem ('user_code') || '' } }) 'X-Transfer-Code': localStorage.getItem ('user_code') || '' } })
.then (res => setPosts ([res.data])) .then (res => setPost (res.data))
.catch (err => console.error ('うんち!', err))) .catch (err => console.error ('うんち!', err)))
}, [id]) }, [id])
if (!(posts.length)) if (!(post))
return <div>Loading...</div> return (
<>
<TagDetailSidebar post={null} />
<MainArea>Loading...</MainArea>
</>)
const post = posts[0] if (post)
document.title = `${ post.title || post.url } | ${ SITE_TITLE }`
document.title = `${ post.title || post.url } | ${ SITE_TITLE }` const url = post ? new URL (post.url) : undefined
const url = new URL (post.url)
return ( return (
<div className="p-4"> <>
{(() => { <TagDetailSidebar post={post} />
if (url.hostname.split ('.').slice (-2).join ('.') === 'nicovideo.jp') <MainArea>
{ {post
return ( ? (
<NicoViewer <div className="p-4">
id={url.pathname.match ( {(() => {
/(?<=\/watch\/)[a-zA-Z0-9]+?(?=\/|$)/)[0]} if (url.hostname.split ('.').slice (-2).join ('.') === 'nicovideo.jp')
width="640" {
height="360" />) return (
} <NicoViewer
else id={url.pathname.match (
return <img src={post.thumbnail} alt={post.url} className="mb-4 w-full" /> /(?<=\/watch\/)[a-zA-Z0-9]+?(?=\/|$)/)[0]}
}) ()} width="640"
<Button onClick={changeViewedFlg} height="360" />)
className={cn ('text-white', }
posts[0]?.viewed ? 'bg-blue-600 hover:bg-blue-700' : 'bg-gray-500 hover:bg-gray-600')}> else
{posts[0]?.viewed ? '閲覧済' : '未閲覧'} return <img src={post.thumbnail} alt={post.url} className="mb-4 w-full" />
</Button> }) ()}
</div>) <Button onClick={changeViewedFlg}
className={cn ('text-white',
post.viewed ? 'bg-blue-600 hover:bg-blue-700' : 'bg-gray-500 hover:bg-gray-600')}>
{post.viewed ? '閲覧済' : '未閲覧'}
</Button>
</div>)
: 'Loading...'}
</MainArea>
</>)
} }
+90 -90
View File
@@ -6,6 +6,7 @@ import NicoViewer from '../components/NicoViewer'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import { toast } from '@/components/ui/use-toast' import { toast } from '@/components/ui/use-toast'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import MainArea from '@/components/layout/MainArea'
import type { Post, Tag } from '@/types' import type { Post, Tag } from '@/types'
@@ -14,7 +15,7 @@ type Props = { posts: Post[]
setPosts: (posts: Post[]) => void } setPosts: (posts: Post[]) => void }
const PostNewPage = () => { export default () => {
const location = useLocation () const location = useLocation ()
const navigate = useNavigate () const navigate = useNavigate ()
@@ -112,99 +113,98 @@ const PostNewPage = () => {
} }
return ( return (
<div className="max-w-xl mx-auto p-4 space-y-4"> <MainArea>
<h1 className="text-2xl font-bold mb-2">稿</h1> <div className="max-w-xl mx-auto p-4 space-y-4">
<h1 className="text-2xl font-bold mb-2">稿</h1>
{/* URL */} {/* URL */}
<div> <div>
<label className="block font-semibold mb-1">URL</label> <label className="block font-semibold mb-1">URL</label>
<input type="text" <input type="text"
placeholder="例:https://www.nicovideo.jp/watch/..." placeholder="例:https://www.nicovideo.jp/watch/..."
value={url} value={url}
onChange={e => setURL (e.target.value)} onChange={e => setURL (e.target.value)}
className="w-full border p-2 rounded" className="w-full border p-2 rounded"
onBlur={handleURLBlur} /> onBlur={handleURLBlur} />
</div>
{/* タイトル */}
<div>
<div className="flex gap-2 mb-1">
<label className="flex-1 block font-semibold"></label>
<label className="flex items-center block gap-1">
<input type="checkbox"
checked={titleAutoFlg}
onChange={e => setTitleAutoFlg (e.target.checked)} />
</label>
</div> </div>
<input type="text"
className="w-full border rounded p-2"
value={title}
placeholder={titleLoading ? 'Loading...' : ''}
onChange={e => setTitle (e.target.value)}
disabled={titleAutoFlg} />
</div>
{/* サムネール */} {/* タイトル */}
<div> <div>
<div className="flex gap-2 mb-1"> <div className="flex gap-2 mb-1">
<label className="block font-semibold flex-1"></label> <label className="flex-1 block font-semibold"></label>
<label className="flex items-center gap-1"> <label className="flex items-center block gap-1">
<input type="checkbox" <input type="checkbox"
checked={thumbnailAutoFlg} checked={titleAutoFlg}
onChange={e => setThumbnailAutoFlg (e.target.checked)} /> onChange={e => setTitleAutoFlg (e.target.checked)} />
</label> </label>
</div>
<input type="text"
className="w-full border rounded p-2"
value={title}
placeholder={titleLoading ? 'Loading...' : ''}
onChange={e => setTitle (e.target.value)}
disabled={titleAutoFlg} />
</div> </div>
{thumbnailAutoFlg
? (thumbnailLoading
? <p className="text-gray-500 text-sm">Loading...</p>
: !(thumbnailPreview) && (
<p className="text-gray-500 text-sm">
URL
</p>))
: (
<input type="file"
accept="image/*"
onChange={e => {
const file = e.target.files?.[0]
if (file)
{
setThumbnailFile (file)
setThumbnailPreview (URL.createObjectURL (file))
}
}} />)}
{thumbnailPreview && (
<img src={thumbnailPreview}
alt="preview"
className="mt-2 max-h-48 rounded border" />)}
</div>
{/* タグ */} {/* サムネール */}
<div> <div>
<label className="block font-semibold"></label> <div className="flex gap-2 mb-1">
<select multiple <label className="block font-semibold flex-1"></label>
value={tagIds.map (String)} <label className="flex items-center gap-1">
onChange={e => { <input type="checkbox"
const values = Array.from (e.target.selectedOptions).map (o => Number (o.value)) checked={thumbnailAutoFlg}
setTagIds (values) onChange={e => setThumbnailAutoFlg (e.target.checked)} />
}}
className="w-full p-2 border rounded h-32"> </label>
{tags.map ((tag: Tag) => ( </div>
<option key={tag.id} value={tag.id}> {thumbnailAutoFlg
{tag.name} ? (thumbnailLoading
</option>))} ? <p className="text-gray-500 text-sm">Loading...</p>
</select> : !(thumbnailPreview) && (
</div> <p className="text-gray-500 text-sm">
URL
</p>))
: (
<input type="file"
accept="image/*"
onChange={e => {
const file = e.target.files?.[0]
if (file)
{
setThumbnailFile (file)
setThumbnailPreview (URL.createObjectURL (file))
}
}} />)}
{thumbnailPreview && (
<img src={thumbnailPreview}
alt="preview"
className="mt-2 max-h-48 rounded border" />)}
</div>
{/* 送信 */} {/* タグ */}
<button onClick={handleSubmit} <div>
className="px-4 py-2 bg-blue-600 text-white rounded disabled:bg-gray-400" <label className="block font-semibold"></label>
disabled={titleLoading || thumbnailLoading}> <select multiple
value={tagIds.map (String)}
</button> onChange={e => {
</div>) const values = Array.from (e.target.selectedOptions).map (o => Number (o.value))
setTagIds (values)
}}
className="w-full p-2 border rounded h-32">
{tags.map ((tag: Tag) => (
<option key={tag.id} value={tag.id}>
{tag.name}
</option>))}
</select>
</div>
{/* 送信 */}
<button onClick={handleSubmit}
className="px-4 py-2 bg-blue-600 text-white rounded disabled:bg-gray-400"
disabled={titleLoading || thumbnailLoading}>
</button>
</div>
</MainArea>)
} }
export default PostNewPage
+19 -18
View File
@@ -2,15 +2,14 @@ import React, { useEffect, useState } from 'react'
import { Link, useLocation } from 'react-router-dom' import { Link, useLocation } from 'react-router-dom'
import axios from 'axios' import axios from 'axios'
import { API_BASE_URL, SITE_TITLE } from '@/config' import { API_BASE_URL, SITE_TITLE } from '@/config'
import TagSidebar from '@/components/TagSidebar'
import MainArea from '@/components/layout/MainArea'
import type { Post, Tag } from '@/types' import type { Post, Tag } from '@/types'
type Props = { posts: Post[]
setPosts: (posts: Post[]) => void }
export default () => {
const PostPage = (props: Props) => { const [posts, setPosts] = useState<Post[]> ([])
const { posts, setPosts } = props
const location = useLocation () const location = useLocation ()
const query = new URLSearchParams (location.search) const query = new URLSearchParams (location.search)
@@ -42,17 +41,19 @@ const PostPage = (props: Props) => {
}, [location.search]) }, [location.search])
return ( return (
<div className="flex flex-wrap gap-4 p-4"> <>
{posts.map (post => ( <TagSidebar posts={posts} />
<Link to={`/posts/${ post.id }`} <MainArea>
key={post.id} <div className="flex flex-wrap gap-4 p-4">
className="w-40 h-40 overflow-hidden rounded-lg shadow-md hover:shadow-lg"> {posts.map (post => (
<img src={post.thumbnail ?? post.thumbnail_base} <Link to={`/posts/${ post.id }`}
className="object-none w-full h-full" /> key={post.id}
</Link> className="w-40 h-40 overflow-hidden rounded-lg shadow-md hover:shadow-lg">
))} <img src={post.thumbnail ?? post.thumbnail_base}
</div>) className="object-none w-full h-full" />
</Link>
))}
</div>
</MainArea>
</>)
} }
export default PostPage
+15 -14
View File
@@ -2,8 +2,10 @@ import React, { useEffect, useState } from 'react'
import axios from 'axios' import axios from 'axios'
import { useParams } from 'react-router-dom' import { useParams } from 'react-router-dom'
import { API_BASE_URL } from '../config' import { API_BASE_URL } from '../config'
import MainArea from '@/components/layout/MainArea'
const TagPage = () => {
export default () => {
const { id } = useParams() const { id } = useParams()
const [posts, setPosts] = useState([]) const [posts, setPosts] = useState([])
const [tagName, setTagName] = useState('') const [tagName, setTagName] = useState('')
@@ -32,18 +34,17 @@ const TagPage = () => {
}, [id]) }, [id])
return ( return (
<div className="container mx-auto p-4"> <MainArea>
<h1 className="text-2xl font-bold mb-4">: {tagName}</h1> <div className="container mx-auto p-4">
<div className="grid grid-cols-4 gap-4"> <h1 className="text-2xl font-bold mb-4">: {tagName}</h1>
{posts.map ((post, index) => ( <div className="grid grid-cols-4 gap-4">
<div key={index} className="border rounded p-2"> {posts.map ((post, index) => (
<img src={post.image_url} alt={post.title} className="w-full h-48 object-cover mb-2" /> <div key={index} className="border rounded p-2">
<h2 className="text-lg font-semibold">{post.title}</h2> <img src={post.image_url} alt={post.title} className="w-full h-48 object-cover mb-2" />
<h2 className="text-lg font-semibold">{post.title}</h2>
</div>
))}
</div> </div>
))} </div>
</div> </MainArea>)
</div>
)
} }
export default TagPage
+12 -12
View File
@@ -3,9 +3,10 @@ import { Link, useParams, useNavigate } from 'react-router-dom'
import ReactMarkdown from 'react-markdown' import ReactMarkdown from 'react-markdown'
import axios from 'axios' import axios from 'axios'
import { API_BASE_URL } from '@/config' import { API_BASE_URL } from '@/config'
import MainArea from '@/components/layout/MainArea'
const WikiDetailPage = () => { export default () => {
const { name } = useParams () const { name } = useParams ()
const navigate = useNavigate () const navigate = useNavigate ()
@@ -26,15 +27,14 @@ const WikiDetailPage = () => {
}, [name]) }, [name])
return ( return (
<div className="prose mx-auto p-4"> <MainArea>
<ReactMarkdown components={{ a: ( <div className="prose mx-auto p-4">
({ href, children }) => (href?.startsWith ('/') <ReactMarkdown components={{ a: (
? <Link to={href!}>{children}</Link> ({ href, children }) => (href?.startsWith ('/')
: <a href={href} target="_blank" rel="noopener noreferrer">{children}</a>)) }}> ? <Link to={href!}>{children}</Link>
{markdown || `このページは存在しません。[新規作成してください](/wiki/new?title=${ name })。`} : <a href={href} target="_blank" rel="noopener noreferrer">{children}</a>)) }}>
</ReactMarkdown> {markdown || `このページは存在しません。[新規作成してください](/wiki/new?title=${ name })。`}
</div>) </ReactMarkdown>
</div>
</MainArea>)
} }
export default WikiDetailPage
+30 -30
View File
@@ -9,13 +9,14 @@ import { cn } from '@/lib/utils'
import MarkdownIt from 'markdown-it' import MarkdownIt from 'markdown-it'
import MdEditor from 'react-markdown-editor-lite' import MdEditor from 'react-markdown-editor-lite'
import 'react-markdown-editor-lite/lib/index.css' import 'react-markdown-editor-lite/lib/index.css'
import MainArea from '@/components/layout/MainArea'
import type { Tag } from '@/types' import type { Tag } from '@/types'
const mdParser = new MarkdownIt const mdParser = new MarkdownIt
const WikiNewPage = () => { export default () => {
const location = useLocation () const location = useLocation ()
const navigate = useNavigate () const navigate = useNavigate ()
@@ -46,35 +47,34 @@ const WikiNewPage = () => {
}, []) }, [])
return ( return (
<div className="max-w-xl mx-auto p-4 space-y-4"> <MainArea>
<h1 className="text-2xl font-bold mb-2"> Wiki </h1> <div className="max-w-xl mx-auto p-4 space-y-4">
<h1 className="text-2xl font-bold mb-2"> Wiki </h1>
{/* タイトル */} {/* タイトル */}
{/* TODO: タグ補完 */} {/* TODO: タグ補完 */}
<div> <div>
<label className="block font-semibold mb-1"></label> <label className="block font-semibold mb-1"></label>
<input type="text" <input type="text"
value={title} value={title}
onChange={e => setTitle (e.target.value)} onChange={e => setTitle (e.target.value)}
className="w-full border p-2 rounded" /> className="w-full border p-2 rounded" />
</div>
{/* 本文 */}
<div>
<label className="block font-semibold mb-1"></label>
<MdEditor value={body}
style={{ height: '500px' }}
renderHTML={text => mdParser.render (text)}
onChange={({ text }) => setBody (text)} />
</div>
{/* 送信 */}
<button onClick={handleSubmit}
className="px-4 py-2 bg-blue-600 text-white rounded disabled:bg-gray-400">
</button>
</div> </div>
</MainArea>)
{/* 本文 */}
<div>
<label className="block font-semibold mb-1"></label>
<MdEditor value={body}
style={{ height: '500px' }}
renderHTML={text => mdParser.render (text)}
onChange={({ text }) => setBody (text)} />
</div>
{/* 送信 */}
<button onClick={handleSubmit}
className="px-4 py-2 bg-blue-600 text-white rounded disabled:bg-gray-400">
</button>
</div>)
} }
export default WikiNewPage