feat: 関聯する Wiki がない TagLink 修正(#107) (#192)

#107

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #192
This commit was merged in pull request #192.
This commit is contained in:
2025-12-28 20:53:32 +09:00
parent c93f8585a1
commit 0344b61557
4 changed files with 115 additions and 40 deletions
+37 -4
View File
@@ -1,5 +1,8 @@
import axios from 'axios'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import { API_BASE_URL } from '@/config'
import { LIGHT_COLOUR_SHADE, DARK_COLOUR_SHADE, TAG_COLOUR } from '@/consts'
import { cn } from '@/lib/utils'
@@ -27,6 +30,27 @@ export default (({ tag,
withWiki = true,
withCount = true,
...props }: Props) => {
const [havingWiki, setHavingWiki] = useState (true)
const wikiExists = async (tagName: string) => {
try
{
await axios.get (`${ API_BASE_URL }/wiki/title/${ encodeURIComponent (tagName) }/exists`)
setHavingWiki (true)
}
catch
{
setHavingWiki (false)
}
}
useEffect (() => {
if (!(linkFlg) || !(withWiki))
return
wikiExists (tag.name)
}, [tag.name, linkFlg, withWiki])
const spanClass = cn (
`text-${ TAG_COLOUR[tag.category] }-${ LIGHT_COLOUR_SHADE }`,
`dark:text-${ TAG_COLOUR[tag.category] }-${ DARK_COLOUR_SHADE }`)
@@ -39,10 +63,19 @@ export default (({ tag,
<>
{(linkFlg && withWiki) && (
<span className="mr-1">
<Link to={`/wiki/${ encodeURIComponent (tag.name) }`}
className={linkClass}>
?
</Link>
{havingWiki
? (
<Link to={`/wiki/${ encodeURIComponent (tag.name) }`}
className={linkClass}>
?
</Link>)
: (
<Link to={`/wiki/${ encodeURIComponent (tag.name) }`}
className="animate-[wiki-blink_.25s_steps(2,end)_infinite]
dark:animate-[wiki-blink-dark_.25s_steps(2,end)_infinite]"
title={`${ tag.name } Wiki が存在しません.`}>
!
</Link>)}
</span>)}
{nestLevel > 0 && (
<span