refactor: enhance blog functionality with related blogs fetching, improved loading states, and tag filtering
This commit is contained in:
@@ -6,11 +6,18 @@ async function Blog({ params: { slug } }) {
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
const blog = await fetchReq(`${API_URL}/api/v1/blog/${slug}`);
|
||||
const blogs = await fetchReq(`${API_URL}/api/v1/blogs`);
|
||||
|
||||
// Get related blogs based on first tag
|
||||
let relatedBlogs = [];
|
||||
if (blog?.tag?.[0]?.id) {
|
||||
const tagId = blog.tag[0].id;
|
||||
const relatedResponse = await fetchReq(`${API_URL}/api/v1/blogs?page=1&limit=12&tag=${tagId}`);
|
||||
relatedBlogs = relatedResponse?.blogs || [];
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<BlogPage blog={blog} blogs={blogs.blogs} />
|
||||
<BlogPage blog={blog} blogs={relatedBlogs} />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user