|
|
@@ -20,25 +20,27 @@ export default () => { |
|
|
|
const location = useLocation () |
|
|
|
const query = new URLSearchParams (location.search) |
|
|
|
const tagsQuery = query.get ('tags') ?? '' |
|
|
|
// const anyFlg = query.get ('match') === 'any' |
|
|
|
const anyFlg = false |
|
|
|
const anyFlg = query.get ('match') === 'any' |
|
|
|
const tags = tagsQuery.split (' ').filter (e => e !== '') |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
void (axios.get (`${ API_BASE_URL }/posts`, { |
|
|
|
params: { tags: tags.join (','), |
|
|
|
match: (anyFlg ? 'any' : 'all') } }) |
|
|
|
.then (res => setPosts (res.data)) |
|
|
|
.then (res => setPosts (toCamel (res.data, { deep: true }))) |
|
|
|
.catch (err => { |
|
|
|
console.error ('Failed to fetch posts:', err) |
|
|
|
setPosts ([]) |
|
|
|
})) |
|
|
|
|
|
|
|
setWikiPage (null) |
|
|
|
if (!(tags.length)) |
|
|
|
return |
|
|
|
void (axios.get (`${ API_BASE_URL }/wiki/title/${ encodeURIComponent (tags.join (' ')) }`) |
|
|
|
.then (res => setWikiPage (toCamel (res.data, { deep: true }))) |
|
|
|
.catch (() => setWikiPage (null))) |
|
|
|
.catch (() => { |
|
|
|
; |
|
|
|
})) |
|
|
|
}, [location.search]) |
|
|
|
|
|
|
|
return ( |
|
|
@@ -58,13 +60,12 @@ export default () => { |
|
|
|
? ( |
|
|
|
<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 ?? post.thumbnail_base} |
|
|
|
className="object-none w-full h-full" /> |
|
|
|
</Link> |
|
|
|
))} |
|
|
|
<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 ?? post.thumbnailBase} |
|
|
|
className="object-none w-full h-full" /> |
|
|
|
</Link>))} |
|
|
|
</div>) |
|
|
|
: '広場には何もありませんよ.'} |
|
|
|
</Tab> |
|
|
|