This commit is contained in:
2025-07-13 02:46:13 +09:00
parent fdf242c060
commit 0c46cf28db
29 changed files with 509 additions and 456 deletions
+72 -70
View File
@@ -1,7 +1,7 @@
import axios from 'axios'
import toCamel from 'camelcase-keys'
import React, { useState, useEffect } from 'react'
import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'
import { useState, useEffect } from 'react'
import { Link, useLocation, useNavigate } from 'react-router-dom'
import { Button } from '@/components/ui/button'
import { API_BASE_URL } from '@/config'
@@ -10,34 +10,34 @@ import { cn } from '@/lib/utils'
import type { Tag, User, WikiPage } from '@/types'
type Props = { user: User | null
setUser: (user: User) => void }
type Props = { user: User | null }
const enum Menu { None,
Post,
User,
Tag,
Wiki }
const Menu = { None: 'None',
Post: 'Post',
User: 'User',
Tag: 'Tag',
Wiki: 'Wiki' } as const
type Menu = typeof Menu[keyof typeof Menu]
export default ({ user, setUser }: Props) => {
export default ({ user }: Props) => {
const location = useLocation ()
const navigate = useNavigate ()
const [selectedMenu, setSelectedMenu] = useState<Menu> (Menu.None)
const [wikiId, setWikiId] = useState<number | null> (WikiIdBus.get ())
const [wikiSearch, setWikiSearch] = useState ('')
const [activeIndex, setActiveIndex] = useState (-1)
const [suggestions, setSuggestions] = useState<WikiPage[]> ([])
const [suggestionsVsbl, setSuggestionsVsbl] = useState (false)
const [tagSearch, setTagSearch] = useState ('')
const [userSearch, setUserSearch] = useState ('')
// const [wikiSearch, setWikiSearch] = useState ('')
// const [activeIndex, setActiveIndex] = useState (-1)
// const [suggestions, setSuggestions] = useState<WikiPage[]> ([])
// const [suggestionsVsbl, setSuggestionsVsbl] = useState (false)
// const [tagSearch, setTagSearch] = useState ('')
// const [userSearch, setUserSearch] = useState ('')
const [postCount, setPostCount] = useState<number | null> (null)
const MyLink = ({ to, title, menu, base }: { to: string
title: string
menu?: Menu
base?: string }) => (
const MyLink = ({ to, title, base }: { to: string
title: string
base?: string }) => (
<Link to={to} className={cn ('hover:text-orange-500 h-full flex items-center',
(location.pathname.startsWith (base ?? to)
? 'bg-gray-700 px-4 font-bold'
@@ -45,55 +45,55 @@ export default ({ user, setUser }: Props) => {
{title}
</Link>)
const whenTagSearchChanged = ev => {
// TODO: 実装
// const whenTagSearchChanged = (ev: React.ChangeEvent<HTMLInputElement>) => {
// // TODO: 実装
//
// setTagSearch (ev.target.value)
//
// const q: string = ev.target.value.split (' ').at (-1)
// if (!(q))
// {
// // setSuggestions ([])
// return
// }
// }
setTagSearch (ev.target.value)
// const whenWikiSearchChanged = (ev: React.ChangeEvent<HTMLInputElement>) => {
// // TODO: 実装
//
// setWikiSearch (ev.target.value)
//
// const q: string = ev.target.value.split (' ').at (-1)
// if (!(q))
// {
// // setSuggestions ([])
// return
// }
// }
const q: string = ev.target.value.split (' ').at (-1)
if (!(q))
{
setSuggestions ([])
return
}
}
// const whenUserSearchChanged = (ev: React.ChangeEvent<HTMLInputElement>) => {
// // TODO: 実装
//
// setUserSearch (ev.target.value)
//
// const q: string = ev.target.value.split (' ').at (-1)
// if (!(q))
// {
// // setSuggestions ([])
// return
// }
// }
const whenWikiSearchChanged = ev => {
// TODO: 実装
// const handleKeyDown = (ev: React.KeyboardEvent<HTMLInputElement>) => {
// if (ev.key === 'Enter' && wikiSearch.length && (!(suggestionsVsbl) || activeIndex < 0))
// {
// navigate (`/wiki/${ encodeURIComponent (wikiSearch) }`)
// setSuggestionsVsbl (false)
// }
// }
setWikiSearch (ev.target.value)
const q: string = ev.target.value.split (' ').at (-1)
if (!(q))
{
setSuggestions ([])
return
}
}
const whenUserSearchChanged = ev => {
// TODO: 実装
setUserSearch (ev.target.value)
const q: string = ev.target.value.split (' ').at (-1)
if (!(q))
{
setSuggestions ([])
return
}
}
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter' && wikiSearch.length && (!(suggestionsVsbl) || activeIndex < 0))
{
navigate (`/wiki/${ encodeURIComponent (wikiSearch) }`)
setSuggestionsVsbl (false)
}
}
const handleTagSelect = (tag: Tag) => {
}
// const handleTagSelect = (tag: Tag) => {
// }
useEffect (() => {
const unsubscribe = WikiIdBus.subscribe (setWikiId)
@@ -120,11 +120,13 @@ export default ({ user, setUser }: Props) => {
void (async () => {
try
{
const { data: pageData } = await axios.get (`${ API_BASE_URL }/wiki/${ wikiId }`)
const wikiPage: WikiPage = toCamel (pageData, { deep: true })
const pageRes = await axios.get (`${ API_BASE_URL }/wiki/${ wikiId }`)
const pageData: any = pageRes.data
const wikiPage = toCamel (pageData, { deep: true }) as WikiPage
const { data: tagData } = await axios.get (`${ API_BASE_URL }/tags/name/${ wikiPage.title }`)
const tag: Tag = toCamel (tagData, { deep: true })
const tagRes = await axios.get (`${ API_BASE_URL }/tags/name/${ wikiPage.title }`)
const tagData: any = tagRes.data
const tag = toCamel (tagData, { deep: true }) as Tag
setPostCount (tag.postCount)
}
@@ -156,7 +158,7 @@ export default ({ user, setUser }: Props) => {
{(() => {
const className = 'bg-gray-700 text-white px-3 flex items-center w-full min-h-[40px]'
const subClass = 'hover:text-orange-500 h-full flex items-center px-3'
const inputBox = 'flex items-center px-3 mx-2'
// const inputBox = 'flex items-center px-3 mx-2'
const Separator = () => <span className="flex items-center px-2">|</span>
switch (selectedMenu)
{