@@ -1,13 +1,11 @@ | |||||
import React, { useEffect, useState } from 'react' | import React, { useEffect, useState } from 'react' | ||||
import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom' | import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom' | ||||
import HomePage from '@/pages/HomePage' | |||||
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 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' | ||||
import WikiPage from '@/pages/WikiPage' | |||||
import WikiNewPage from '@/pages/WikiNewPage' | import WikiNewPage from '@/pages/WikiNewPage' | ||||
import WikiDetailPage from '@/pages/WikiDetailPage' | import WikiDetailPage from '@/pages/WikiDetailPage' | ||||
import { API_BASE_URL } from '@/config' | import { API_BASE_URL } from '@/config' | ||||
@@ -15,21 +13,7 @@ import axios from 'axios' | |||||
import { Toaster } from '@/components/ui/toaster' | import { Toaster } from '@/components/ui/toaster' | ||||
import { camelizeKeys } from 'humps' | import { camelizeKeys } from 'humps' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string } | |||||
type Post = { id: number | |||||
url: string | |||||
title: string | |||||
thumbnail: string | |||||
tags: Tag[] | |||||
viewed: boolean } | |||||
type User = { id: number | |||||
name: string | null | |||||
inheritanceCode: string | |||||
role: string } | |||||
import type { Post, Tag, User } from '@/types' | |||||
const App = () => { | const App = () => { | ||||
@@ -83,7 +67,6 @@ const App = () => { | |||||
<Route path="/posts/new" element={<PostNewPage />} /> | <Route path="/posts/new" element={<PostNewPage />} /> | ||||
<Route path="/posts/:id" element={<PostDetailPage posts={posts} setPosts={setPosts} />} /> | <Route path="/posts/:id" element={<PostDetailPage posts={posts} setPosts={setPosts} />} /> | ||||
<Route path="/tags/:tag" element={<TagPage />} /> | <Route path="/tags/:tag" element={<TagPage />} /> | ||||
<Route path="/wiki" element={<WikiPage />} /> | |||||
<Route path="/wiki/:name" element={<WikiDetailPage />} /> | <Route path="/wiki/:name" element={<WikiDetailPage />} /> | ||||
<Route path="/wiki/new" element={<WikiNewPage />} /> | <Route path="/wiki/new" element={<WikiNewPage />} /> | ||||
{/* <Route path="/wiki/:id/edit" element={<WikiEditPage />} /> */} | {/* <Route path="/wiki/:id/edit" element={<WikiEditPage />} /> */} | ||||
@@ -6,18 +6,10 @@ import { Input } from '@/components/ui/input' | |||||
import { toast } from '@/components/ui/use-toast' | import { toast } from '@/components/ui/use-toast' | ||||
import axios from 'axios' | import axios from 'axios' | ||||
import { Link, useNavigate, useLocation } from 'react-router-dom' | import { Link, useNavigate, useLocation } from 'react-router-dom' | ||||
import { API_BASE_URL } from '../config' | |||||
import { API_BASE_URL } from '@/config' | |||||
import { camelizeKeys } from 'humps' | import { camelizeKeys } from 'humps' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string | |||||
count?: number } | |||||
type User = { id: number | |||||
name: string | null | |||||
inheritanceCode: string | |||||
role: string } | |||||
import type { Tag, User } from '@/types' | |||||
type Props = { visible: boolean | type Props = { visible: boolean | ||||
onVisibleChange: (visible: boolean) => void | onVisibleChange: (visible: boolean) => void | ||||
@@ -1,13 +1,10 @@ | |||||
import React, { useEffect, useState } from 'react' | import React, { useEffect, useState } from 'react' | ||||
import axios from 'axios' | import axios from 'axios' | ||||
import { Link, useNavigate, useLocation } from 'react-router-dom' | import { Link, useNavigate, useLocation } from 'react-router-dom' | ||||
import { API_BASE_URL } from '../config' | |||||
import { API_BASE_URL } from '@/config' | |||||
import TagSearchBox from './TagSearchBox' | import TagSearchBox from './TagSearchBox' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string | |||||
count?: number } | |||||
import type { Tag } from '@/types' | |||||
const TagSearch: React.FC = () => { | const TagSearch: React.FC = () => { | ||||
@@ -3,10 +3,7 @@ import axios from 'axios' | |||||
import { Link, useNavigate, useLocation } from 'react-router-dom' | import { Link, useNavigate, useLocation } from 'react-router-dom' | ||||
import { API_BASE_URL } from '../config' | import { API_BASE_URL } from '../config' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string | |||||
count?: number } | |||||
import type { Tag } from '@/types' | |||||
type Props = { suggestions: Tag[] | type Props = { suggestions: Tag[] | ||||
activeIndex: number | activeIndex: number | ||||
@@ -4,22 +4,10 @@ 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' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string } | |||||
import type { Post, Tag } from '@/types' | |||||
type TagByCategory = { [key: string]: Tag[] } | type TagByCategory = { [key: string]: Tag[] } | ||||
type OriginalTag = { id: number | |||||
name: string | |||||
category: string } | |||||
type Post = { id: number | |||||
url: string | |||||
title: string | |||||
thumbnail: string | |||||
tags: Tag[] } | |||||
type Props = { posts: Post[] | type Props = { posts: Post[] | ||||
setPosts: (posts: Post[]) => void } | setPosts: (posts: Post[]) => void } | ||||
@@ -4,10 +4,7 @@ import SettingsDialogue from './SettingsDialogue' | |||||
import { Button } from './ui/button' | import { Button } from './ui/button' | ||||
import clsx from 'clsx' | import clsx from 'clsx' | ||||
type User = { id: number | |||||
name: string | null | |||||
inheritanceCode: string | |||||
role: string } | |||||
import type { User } from '@/types' | |||||
type Props = { user: User | type Props = { user: User | ||||
setUser: (user: User) => void } | setUser: (user: User) => void } | ||||
@@ -1,19 +0,0 @@ | |||||
import MdEditor from 'react-markdown-editor-lite' | |||||
import 'react-markdown-editor-lite/lib/index.css' | |||||
import { marked } from 'marked' | |||||
type Props = { value: string | |||||
onChange: (text: string) => void | |||||
onSave: () => void } | |||||
const WikiEditor = ({ value, onChange, onSave }) => ( | |||||
<div className="wiki-editor"> | |||||
<MdEditor value={value} | |||||
style={{ height: '500px' }} | |||||
renderHTML={text => marked (text)} /> | |||||
<button onClick={onSave}>保存</button> | |||||
</div>) | |||||
export default WikiEditor |
@@ -1,40 +0,0 @@ | |||||
import React, { useEffect, useState } from 'react' | |||||
import { Link } from 'react-router-dom' | |||||
import axios from 'axios' | |||||
import { API_BASE_URL, SITE_TITLE } from '../config' | |||||
const HomePage = () => { | |||||
const [posts, setPosts] = useState([]) | |||||
useEffect(() => { | |||||
const fetchPosts = async () => { | |||||
try { | |||||
const response = await axios.get(`${ API_BASE_URL }/posts`) | |||||
setPosts(response.data) | |||||
} catch (error) { | |||||
console.error('Failed to fetch posts:', error) | |||||
} | |||||
} | |||||
fetchPosts() | |||||
document.title = `${ SITE_TITLE } 〜 ぼざクリも、ぼざろ外も、外伝もあるんだよ。` | |||||
}, []) | |||||
return ( | |||||
<div className="flex flex-wrap gap-4 p-4"> | |||||
{posts.map (post => ( | |||||
<Link | |||||
to={`/posts/${post.id}`} | |||||
key={post.id} | |||||
className="w-40 h-40 overflow-hidden rounded-lg shadow-md hover:shadow-lg" | |||||
> | |||||
<img | |||||
src={post.thumbnail} | |||||
className="object-cover w-full h-full" | |||||
/> | |||||
</Link> | |||||
))} | |||||
</div> | |||||
) | |||||
} | |||||
export default HomePage |
@@ -7,16 +7,7 @@ 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' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string } | |||||
type Post = { id: number | |||||
url: string | |||||
title: string | |||||
thumbnail: string | |||||
tags: Tag[] | |||||
viewed: boolean } | |||||
import type { Post, Tag } from '@/types' | |||||
type Props = { posts: Post[] | type Props = { posts: Post[] | ||||
setPosts: (posts: Post[]) => void } | setPosts: (posts: Post[]) => void } | ||||
@@ -7,16 +7,8 @@ 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' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string } | |||||
type Post = { id: number | |||||
url: string | |||||
title: string | |||||
thumbnail: string | |||||
tags: Tag[] | |||||
viewed: boolean } | |||||
import type { Post, Tag } from '@/types' | |||||
type Props = { posts: Post[] | type Props = { posts: Post[] | ||||
setPosts: (posts: Post[]) => void } | setPosts: (posts: Post[]) => void } | ||||
@@ -1,18 +1,9 @@ | |||||
import React, { useEffect, useState } from 'react' | 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' | |||||
type Tag = { id: number | |||||
name: string | |||||
category: string } | |||||
type Post = { id: number | |||||
url: string | |||||
title: string | |||||
thumbnail: string | |||||
tags: Tag[] | |||||
viewed: boolean } | |||||
import type { Post, Tag } from '@/types' | |||||
type Props = { posts: Post[] | type Props = { posts: Post[] | ||||
setPosts: (posts: Post[]) => void } | setPosts: (posts: Post[]) => void } | ||||
@@ -10,9 +10,7 @@ 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' | ||||
type Tag = { id: number | |||||
name: string | |||||
category: string } | |||||
import type { Tag } from '@/types' | |||||
const mdParser = new MarkdownIt | const mdParser = new MarkdownIt | ||||
@@ -1,25 +0,0 @@ | |||||
import axios from 'axios' | |||||
import { useState, useEffect } from 'react' | |||||
import WikiEditor from '@/components/WikiEditor' | |||||
import { API_BASE_URL } from '../config' | |||||
const WikiPage = () => { | |||||
const [text, setText] = useState ('') | |||||
useEffect (() => { | |||||
void (axios.get (`${ API_BASE_URL }/wiki/load`, { params: { page: 'xxx' } }) | |||||
.then (res => setText (res.data.markdown))) | |||||
}, []) | |||||
const save = () => { | |||||
void (axios.post ('/api/wiki/save', { page: 'xxx', | |||||
markdown: text }) | |||||
.catch (err => console.error ('保存失敗', err))) | |||||
} | |||||
return <WikiEditor value={text} onChange={setText} onSave={save} /> | |||||
} | |||||
export default WikiPage |
@@ -0,0 +1,19 @@ | |||||
export type Post = { | |||||
id: number | |||||
url: string | |||||
title: string | |||||
thumbnail: string | |||||
tags: Tag[] | |||||
viewed: boolean } | |||||
export type Tag = { | |||||
id: number | |||||
name: string | |||||
category: string | |||||
count?: number} | |||||
export type User = { | |||||
id: number | |||||
name: string | null | |||||
inheritanceCode: string | |||||
role: string } |