Skip to content

Commit 708abd2

Browse files
committed
fix: build
1 parent ddc0670 commit 708abd2

2 files changed

Lines changed: 28 additions & 49 deletions

File tree

app/(public)/blog/[id]/page.tsx

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,9 @@
1-
"use client";
2-
import { notFound } from "next/navigation";
3-
import React, { useEffect, useState } from "react";
4-
import { useParams } from "next/navigation";
51
import BlogDeatails from "@/components/blog/details";
6-
import { blogData } from "@/static/blog";
7-
import { BlogItem } from "@/types/blog";
8-
9-
const BlogPage = () => {
10-
const params = useParams();
11-
const [isLoading, setIsLoading] = useState(true);
12-
const [post, setPost] = useState<BlogItem | null>(null);
13-
14-
useEffect(() => {
15-
if (params.id) {
16-
const foundPost = blogData.find((item) => item.id === params.id);
17-
setPost(foundPost || null);
18-
setIsLoading(false);
19-
}
20-
}, [params.id]);
21-
22-
if (isLoading) {
23-
return <div>Loading...</div>;
24-
}
25-
26-
if (!post) {
27-
notFound();
28-
}
292

3+
export default function page() {
304
return (
315
<div>
32-
<BlogDeatails
33-
id={post.id}
34-
image={post.image}
35-
title={post.title}
36-
description={post.description}
37-
content={post.content}
38-
author={post.author}
39-
/>
6+
<BlogDeatails />
407
</div>
418
);
42-
};
43-
44-
export default BlogPage;
9+
}

components/blog/details/index.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1-
import React from "react";
1+
"use client";
2+
3+
import React, { useEffect, useState } from "react";
4+
import { useParams } from "next/navigation";
5+
import { blogData } from "@/static/blog";
26
import { BlogItem } from "@/types/blog";
37
import DetailHero from "./DetailHero";
48
import DetailContent from "./DetailContent";
59

6-
const BlogDeatails = ({ image, title, content, author }: BlogItem) => {
10+
const BlogDeatails = () => {
11+
const params = useParams(); // get id from URL
12+
const [post, setPost] = useState<BlogItem | null>(null);
13+
14+
useEffect(() => {
15+
if (params?.id) {
16+
const found = blogData.find((b) => b.id.toString() === params.id);
17+
setPost(found || null);
18+
}
19+
}, [params?.id]);
20+
21+
if (!post) return <div>Loading or blog not found...</div>;
22+
723
return (
824
<div className="flex flex-col">
925
<DetailHero
10-
imageSrc={image}
11-
title={title}
12-
authorName={author.name}
13-
authorAvatar={author.avatar}
14-
date={author.date}
15-
readTime={author.readTime}
16-
className=""
26+
imageSrc={post.image}
27+
title={post.title}
28+
authorName={post.author.name}
29+
authorAvatar={post.author.avatar}
30+
date={post.author.date}
31+
readTime={post.author.readTime}
1732
/>
18-
19-
<DetailContent content={content} />
33+
<DetailContent content={post.content} />
2034
</div>
2135
);
2236
};

0 commit comments

Comments
 (0)