Skip to content

Commit 77e2e29

Browse files
committed
refactor: update Authors component to fetch data from Firestore and replace LatestArticles with LatestPosts
1 parent f001861 commit 77e2e29

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
lines changed

app/page.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Authors from "@/components/Authors/Authors";
2-
import LatestArticles from "@/components/LatestPosts/LatestPosts";
2+
import LatestPosts from "@/components/LatestPosts/LatestPosts";
33
import NewsLoading from "@/components/NewsTicker/loading";
44
import AuthorsLoading from "@/components/Authors/loading";
55
import NewsTicker from "@/components/NewsTicker/NewsTicker";
@@ -27,26 +27,14 @@ export default function Home() {
2727
<NewsTicker />
2828
</Suspense>
2929

30-
<LatestArticles />
31-
32-
{/* <Subheading
33-
className="text-subheading"
34-
url="/podcasts"
35-
linkText="All episodes"
36-
>
37-
Podcast
38-
</Subheading> */}
39-
{/*
40-
<Suspense fallback={<LatestPodcastsLoading />}>
41-
<LatestPodcasts />
42-
</Suspense> */}
30+
<LatestPosts />
4331

4432
<Subheading
4533
className="text-subheading"
4634
url="/authors"
47-
linkText="All authors"
35+
linkText="Full Team"
4836
>
49-
Authors
37+
Team
5038
</Subheading>
5139

5240
<Suspense fallback={<AuthorsLoading />}>

components/Authors/Authors.tsx

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,64 @@
1-
import { ArticleType, getArticles } from "@/app/functions/getArticles";
1+
import { collection, getDocs } from "firebase/firestore";
2+
import { db } from "@/lib/firebase";
23
import Image from "next/image";
34
import Link from "next/link";
45

6+
// Define the structure of an author
7+
type AuthorType = {
8+
id: string;
9+
slug: string;
10+
name: string;
11+
avatar: string;
12+
imgAlt: string;
13+
job: string;
14+
city: string;
15+
};
16+
17+
// Function to fetch authors from Firestore
18+
const getAuthors = async (): Promise<AuthorType[]> => {
19+
const authorsCollection = collection(db, "authors");
20+
const authorsSnapshot = await getDocs(authorsCollection);
21+
22+
return authorsSnapshot.docs.map((doc) => {
23+
const data = doc.data() as AuthorType;
24+
return {
25+
...data,
26+
id: doc.id,
27+
};
28+
});
29+
};
30+
531
export default async function Authors() {
6-
const data: ArticleType[] = await getArticles();
32+
const data: AuthorType[] = await getAuthors();
733

834
return (
9-
<div className="grid grid-cols-1 lg:grid-cols-2 mb-48 max-w-[95rem] w-full mx-auto border border-black border-collapse">
10-
{data.map((article) => (
35+
<div className="grid grid-cols-1 lg:grid-cols-2 mb-48 max-w-[95rem] w-full mx-auto border border-white border-collapse">
36+
{data.map((author) => (
1137
<article
12-
className="flex flex-col sm:flex-row sm:items-center gap-4 sm:gap-8 md:gap-12 p-4 md:p-8 border border-black"
13-
key={article.id}
38+
className="flex flex-col sm:flex-row sm:items-center gap-4 sm:gap-8 md:gap-12 p-4 md:p-8 border border-white"
39+
key={author.id}
1440
>
15-
<Link href={`authors/${article.slug}`}>
41+
<Link href={`/authors/${author.slug}`}>
1642
<Image
1743
className="w-[9.375rem] h-[9.375rem] object-cover rounded-full hover:scale-105 transition"
18-
src={article.avatar}
19-
alt={article.imgAlt}
44+
src={author.avatar}
45+
alt={author.imgAlt}
2046
width={150}
2147
height={150}
2248
/>
2349
</Link>
2450
<article>
2551
<p className="heading3-title mb-4">
26-
<Link href={`/authors/${article.slug}`}>{article.author}</Link>
52+
<Link href={`/authors/${author.slug}`}>{author.name}</Link>
2753
</p>
2854
<div className="flex gap-8">
2955
<span className="flex">
30-
<p className="font-semibold pr-2">Job</p>
31-
<p className="">{article.job}</p>
56+
<p className="font-semibold pr-2">Job:</p>
57+
<p className="">{author.job}</p>
3258
</span>
3359
<span className="flex">
34-
<p className="font-semibold pr-2">City</p>
35-
<p className="">{article.city}</p>
60+
<p className="font-semibold pr-2">City:</p>
61+
<p className="">{author.city}</p>
3662
</span>
3763
</div>
3864
</article>

components/Subheading.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Link from "next/link";
2+
import { RiArrowRightLine } from "react-icons/ri"; // Import React Icon
23

34
type SubheadingProps = {
45
children: React.ReactNode;
@@ -27,11 +28,8 @@ export default function Subheading({
2728
<p className="uppercase font-semibold text-lg hidden sm:block md:text-[2rem]">
2829
{linkText}
2930
</p>
30-
<img
31-
className="w-fit h-fit"
32-
src="/icons/ri_arrow-right-line.svg"
33-
alt="A right black arrow"
34-
/>
31+
{/* Replace <img> with React Icon */}
32+
<RiArrowRightLine className="text-3xl sm:text-4xl" />
3533
</Link>
3634
</div>
3735
);

public/icons/ri_arrow-right-line.svg

Lines changed: 12 additions & 3 deletions
Loading

0 commit comments

Comments
 (0)