From 3363fcd2ae04428eee78a3e0129ee50af95b1fce Mon Sep 17 00:00:00 2001 From: miteruzo Date: Thu, 12 Jun 2025 00:46:06 +0900 Subject: [PATCH] =?UTF-8?q?#26=20=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.tsx | 19 +--------- frontend/src/components/SettingsDialogue.tsx | 12 +----- frontend/src/components/TagSearch.tsx | 7 +--- frontend/src/components/TagSearchBox.tsx | 5 +-- frontend/src/components/TagSidebar.tsx | 14 +------ frontend/src/components/TopNav.tsx | 5 +-- frontend/src/components/WikiEditor/index.tsx | 19 ---------- frontend/src/pages/HomePage.tsx | 40 -------------------- frontend/src/pages/PostDetailPage.tsx | 11 +----- frontend/src/pages/PostNewPage.tsx | 12 +----- frontend/src/pages/PostPage.tsx | 13 +------ frontend/src/pages/WikiNewPage.tsx | 4 +- frontend/src/pages/WikiPage.tsx | 25 ------------ frontend/src/types.ts | 19 ++++++++++ 14 files changed, 33 insertions(+), 172 deletions(-) delete mode 100644 frontend/src/components/WikiEditor/index.tsx delete mode 100644 frontend/src/pages/HomePage.tsx delete mode 100644 frontend/src/pages/WikiPage.tsx create mode 100644 frontend/src/types.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 649c409..3cd0874 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,13 +1,11 @@ import React, { useEffect, useState } from 'react' import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom' -import HomePage from '@/pages/HomePage' import TagPage from '@/pages/TagPage' import TopNav from '@/components/TopNav' import TagSidebar from '@/components/TagSidebar' import PostPage from '@/pages/PostPage' import PostNewPage from '@/pages/PostNewPage' import PostDetailPage from '@/pages/PostDetailPage' -import WikiPage from '@/pages/WikiPage' import WikiNewPage from '@/pages/WikiNewPage' import WikiDetailPage from '@/pages/WikiDetailPage' import { API_BASE_URL } from '@/config' @@ -15,21 +13,7 @@ import axios from 'axios' import { Toaster } from '@/components/ui/toaster' 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 = () => { @@ -83,7 +67,6 @@ const App = () => { } /> } /> } /> - } /> } /> } /> {/* } /> */} diff --git a/frontend/src/components/SettingsDialogue.tsx b/frontend/src/components/SettingsDialogue.tsx index 368aed7..b3267c2 100644 --- a/frontend/src/components/SettingsDialogue.tsx +++ b/frontend/src/components/SettingsDialogue.tsx @@ -6,18 +6,10 @@ import { Input } from '@/components/ui/input' import { toast } from '@/components/ui/use-toast' import axios from 'axios' import { Link, useNavigate, useLocation } from 'react-router-dom' -import { API_BASE_URL } from '../config' +import { API_BASE_URL } from '@/config' 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 onVisibleChange: (visible: boolean) => void diff --git a/frontend/src/components/TagSearch.tsx b/frontend/src/components/TagSearch.tsx index a6b51c3..f060a7b 100644 --- a/frontend/src/components/TagSearch.tsx +++ b/frontend/src/components/TagSearch.tsx @@ -1,13 +1,10 @@ import React, { useEffect, useState } from 'react' import axios from 'axios' import { Link, useNavigate, useLocation } from 'react-router-dom' -import { API_BASE_URL } from '../config' +import { API_BASE_URL } from '@/config' import TagSearchBox from './TagSearchBox' -type Tag = { id: number - name: string - category: string - count?: number } +import type { Tag } from '@/types' const TagSearch: React.FC = () => { diff --git a/frontend/src/components/TagSearchBox.tsx b/frontend/src/components/TagSearchBox.tsx index 8ec9714..3f5e3c3 100644 --- a/frontend/src/components/TagSearchBox.tsx +++ b/frontend/src/components/TagSearchBox.tsx @@ -3,10 +3,7 @@ import axios from 'axios' import { Link, useNavigate, useLocation } from 'react-router-dom' 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[] activeIndex: number diff --git a/frontend/src/components/TagSidebar.tsx b/frontend/src/components/TagSidebar.tsx index 16db20a..264d753 100644 --- a/frontend/src/components/TagSidebar.tsx +++ b/frontend/src/components/TagSidebar.tsx @@ -4,22 +4,10 @@ import { Link, useParams } from 'react-router-dom' import { API_BASE_URL } from '../config' import TagSearch from './TagSearch' -type Tag = { id: number - name: string - category: string } +import type { Post, Tag } from '@/types' 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[] setPosts: (posts: Post[]) => void } diff --git a/frontend/src/components/TopNav.tsx b/frontend/src/components/TopNav.tsx index 83e1468..df0304b 100644 --- a/frontend/src/components/TopNav.tsx +++ b/frontend/src/components/TopNav.tsx @@ -4,10 +4,7 @@ import SettingsDialogue from './SettingsDialogue' import { Button } from './ui/button' import clsx from 'clsx' -type User = { id: number - name: string | null - inheritanceCode: string - role: string } +import type { User } from '@/types' type Props = { user: User setUser: (user: User) => void } diff --git a/frontend/src/components/WikiEditor/index.tsx b/frontend/src/components/WikiEditor/index.tsx deleted file mode 100644 index 678647e..0000000 --- a/frontend/src/components/WikiEditor/index.tsx +++ /dev/null @@ -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 }) => ( -
- marked (text)} /> - -
) - - -export default WikiEditor diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx deleted file mode 100644 index 4d1c8a0..0000000 --- a/frontend/src/pages/HomePage.tsx +++ /dev/null @@ -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 ( -
- {posts.map (post => ( - - - - ))} -
- ) -} - -export default HomePage diff --git a/frontend/src/pages/PostDetailPage.tsx b/frontend/src/pages/PostDetailPage.tsx index 46546ec..87a35ef 100644 --- a/frontend/src/pages/PostDetailPage.tsx +++ b/frontend/src/pages/PostDetailPage.tsx @@ -7,16 +7,7 @@ import { Button } from '@/components/ui/button' import { toast } from '@/components/ui/use-toast' 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[] setPosts: (posts: Post[]) => void } diff --git a/frontend/src/pages/PostNewPage.tsx b/frontend/src/pages/PostNewPage.tsx index 9aba795..c61e366 100644 --- a/frontend/src/pages/PostNewPage.tsx +++ b/frontend/src/pages/PostNewPage.tsx @@ -7,16 +7,8 @@ import { Button } from '@/components/ui/button' import { toast } from '@/components/ui/use-toast' 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[] setPosts: (posts: Post[]) => void } diff --git a/frontend/src/pages/PostPage.tsx b/frontend/src/pages/PostPage.tsx index 50539f0..cb7d7c8 100644 --- a/frontend/src/pages/PostPage.tsx +++ b/frontend/src/pages/PostPage.tsx @@ -1,18 +1,9 @@ import React, { useEffect, useState } from 'react' import { Link, useLocation } from 'react-router-dom' 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[] setPosts: (posts: Post[]) => void } diff --git a/frontend/src/pages/WikiNewPage.tsx b/frontend/src/pages/WikiNewPage.tsx index 5499f21..2f46021 100644 --- a/frontend/src/pages/WikiNewPage.tsx +++ b/frontend/src/pages/WikiNewPage.tsx @@ -10,9 +10,7 @@ import MarkdownIt from 'markdown-it' import MdEditor from 'react-markdown-editor-lite' 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 diff --git a/frontend/src/pages/WikiPage.tsx b/frontend/src/pages/WikiPage.tsx deleted file mode 100644 index 49343eb..0000000 --- a/frontend/src/pages/WikiPage.tsx +++ /dev/null @@ -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 -} - - -export default WikiPage diff --git a/frontend/src/types.ts b/frontend/src/types.ts new file mode 100644 index 0000000..22c3069 --- /dev/null +++ b/frontend/src/types.ts @@ -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 }