Skip to content

Commit ce2b618

Browse files
committed
add data from fire store
1 parent 3453c1e commit ce2b618

File tree

3 files changed

+57
-21
lines changed

3 files changed

+57
-21
lines changed

src/layout/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import Footer from "./Footer";
55

66
const Layout = () => {
77
return (
8-
<div className="flex flex-col md:flex-row min-h-screen justify-between p-4 md:p-0">
8+
<div className="flex h-screen">
99
<Sidebar />
1010
<div className="flex flex-col w-full">
11-
<div className="flex flex-col flex-1 w-full mx-auto">
11+
<div className="flex-1 h-full overflow-auto">
1212
<Outlet />
1313
</div>
1414
<Footer />

src/layout/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const Sidebar = () => {
9393
className={`block w-full py-2 px-4 text-center mb-2 rounded-md ${
9494
item.title === "Register"
9595
? "c-black bc-green"
96-
: "c-green border border-green"
96+
: "c-green border border-green bc-black"
9797
}`}
9898
>
9999
{item.title}

src/pages/Home/Home.tsx

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ interface Blog {
1212
}
1313

1414
const Home = () => {
15+
//state
1516
const [blogs, setBlogs] = useState<Blog[]>([]);
17+
const [loading, setLoading] = useState(true);
1618

19+
//service
1720
useEffect(() => {
1821
const fetchBlogs = async () => {
1922
try {
@@ -26,31 +29,64 @@ const Home = () => {
2629
console.log(blogsData);
2730
} catch (error) {
2831
console.error("Error fetching blogs:", error);
32+
} finally {
33+
setLoading(false);
2934
}
3035
};
3136

3237
fetchBlogs();
3338
}, []);
3439

40+
if (loading) {
41+
return (
42+
<div className="flex justify-center items-center h-screen">
43+
<div className="loading loading-spinner"></div>
44+
</div>
45+
);
46+
}
47+
3548
return (
36-
<div>
37-
<h1>Blogs</h1>
38-
{blogs.map((blog) => (
39-
<div key={blog.id}>
40-
<h2>{blog.title}</h2>
41-
<p>{blog.content}</p>
42-
<p>
43-
<strong>Author:</strong> {blog.author}
44-
</p>
45-
<p>
46-
<strong>Tags:</strong> {blog.tags.join(", ")}
47-
</p>
48-
<p>
49-
<strong>Created At:</strong>{" "}
50-
{new Date(blog.createdAt.seconds * 1000).toLocaleString()}
51-
</p>
52-
</div>
53-
))}
49+
<div className="flex flex-col p-[3em] gap-[2em]">
50+
<div className="flex flex-col items-center w-10">
51+
<div className="w-4 h-0.5 bc-green"></div>
52+
<h1>Latest</h1>
53+
</div>
54+
{blogs.length === 0 ? (
55+
<p className="text-center text-lg font-medium">There is no blog.</p>
56+
) : (
57+
blogs.map((blog) => (
58+
<div key={blog.id} className="flex items-start h-[13rem] mb-4">
59+
<div className="flex flex-col items-start justify-between relative h-44">
60+
<p className="text-left text-3xl uppercase font-semibold w-20">
61+
{new Date(blog.createdAt.seconds * 1000).toLocaleDateString(
62+
"en-GB",
63+
{
64+
day: "numeric",
65+
month: "short",
66+
}
67+
)}
68+
</p>
69+
<p className="-rotate-90 absolute -left-6 bottom-5 text-xs w-36 text-center">
70+
{blog.author}
71+
</p>
72+
</div>
73+
<div className="flex flex-col justify-between h-full">
74+
<h2 className="c-green text-3xl font-semibold">{blog.title}</h2>
75+
<p className="text-sm my-3">{blog.content}</p>
76+
<div>
77+
{blog.tags.map((tagItem, index) => (
78+
<span
79+
key={index}
80+
className="border border-green mx-1 px-2 py-1 text-xs rounded-full c-green"
81+
>
82+
#{tagItem}
83+
</span>
84+
))}
85+
</div>
86+
</div>
87+
</div>
88+
))
89+
)}
5490
</div>
5591
);
5692
};

0 commit comments

Comments
 (0)