#49 ページの移動
このコミットが含まれているのは:
@@ -1,50 +0,0 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import axios from 'axios'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { API_BASE_URL } from '../config'
|
||||
import MainArea from '@/components/layout/MainArea'
|
||||
|
||||
|
||||
export default () => {
|
||||
const { id } = useParams()
|
||||
const [posts, setPosts] = useState([])
|
||||
const [tagName, setTagName] = useState('')
|
||||
|
||||
useEffect (() => {
|
||||
const fetchTag = async () => {
|
||||
try {
|
||||
const response = await axios.get (`${API_BASE_URL}/tags/${id}`)
|
||||
setTagName (response.data.name)
|
||||
} catch (error) {
|
||||
console.error ('Error fetching tag:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchPosts = async () => {
|
||||
try {
|
||||
const response = await axios.get (`${API_BASE_URL}/tags/${id}/posts`)
|
||||
setPosts (response.data)
|
||||
} catch (error) {
|
||||
console.error ('Error fetching posts:', error)
|
||||
}
|
||||
}
|
||||
|
||||
fetchTag ()
|
||||
fetchPosts ()
|
||||
}, [id])
|
||||
|
||||
return (
|
||||
<MainArea>
|
||||
<div className="container mx-auto p-4">
|
||||
<h1 className="text-2xl font-bold mb-4">タグ: {tagName}</h1>
|
||||
<div className="grid grid-cols-4 gap-4">
|
||||
{posts.map ((post, index) => (
|
||||
<div key={index} className="border rounded p-2">
|
||||
<img src={post.image_url} alt={post.title} className="w-full h-48 object-cover mb-2" />
|
||||
<h2 className="text-lg font-semibold">{post.title}</h2>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</MainArea>)
|
||||
}
|
||||
新しい課題から参照
ユーザをブロックする