ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

64 lines
1.9 KiB

  1. import React, { useEffect, useState } from 'react'
  2. import { Helmet } from 'react-helmet'
  3. import { Link, useLocation } from 'react-router-dom'
  4. import axios from 'axios'
  5. import { API_BASE_URL, SITE_TITLE } from '@/config'
  6. import TagSidebar from '@/components/TagSidebar'
  7. import MainArea from '@/components/layout/MainArea'
  8. import type { Post, Tag } from '@/types'
  9. export default () => {
  10. const [posts, setPosts] = useState<Post[]> ([])
  11. const location = useLocation ()
  12. const query = new URLSearchParams (location.search)
  13. const tagsQuery = query.get ('tags') ?? ''
  14. // const anyFlg = query.get ('match') === 'any'
  15. const anyFlg = false
  16. const tags = tagsQuery.split (' ').filter (e => e !== '')
  17. useEffect(() => {
  18. const fetchPosts = async () => {
  19. try
  20. {
  21. const res = await axios.get (`${ API_BASE_URL }/posts`, {
  22. params: { tags: tags.join (','),
  23. match: (anyFlg ? 'any' : 'all') } })
  24. setPosts (res.data)
  25. }
  26. catch (error)
  27. {
  28. console.error ('Failed to fetch posts:', error)
  29. setPosts ([])
  30. }
  31. }
  32. fetchPosts()
  33. }, [location.search])
  34. return (
  35. <>
  36. <Helmet>
  37. <title>
  38. {tags.length
  39. ? `${ tags.join (anyFlg ? ' or ' : ' and ') } | ${ SITE_TITLE }`
  40. : `${ SITE_TITLE } 〜 ぼざクリも、ぼざろ外も、外伝もあるんだよ`}
  41. </title>
  42. </Helmet>
  43. <TagSidebar posts={posts} />
  44. <MainArea>
  45. <div className="flex flex-wrap gap-4 p-4">
  46. {posts.map (post => (
  47. <Link to={`/posts/${ post.id }`}
  48. key={post.id}
  49. className="w-40 h-40 overflow-hidden rounded-lg shadow-md hover:shadow-lg">
  50. <img src={post.thumbnail ?? post.thumbnail_base}
  51. className="object-none w-full h-full" />
  52. </Link>
  53. ))}
  54. </div>
  55. </MainArea>
  56. </>)
  57. }