|
1 |
| -import { ArticleType, getArticles } from "@/app/functions/getArticles"; |
| 1 | +import { collection, getDocs } from "firebase/firestore"; |
| 2 | +import { db } from "@/lib/firebase"; |
2 | 3 | import Image from "next/image";
|
3 | 4 | import Link from "next/link";
|
4 | 5 |
|
| 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 | + |
5 | 31 | export default async function Authors() {
|
6 |
| - const data: ArticleType[] = await getArticles(); |
| 32 | + const data: AuthorType[] = await getAuthors(); |
7 | 33 |
|
8 | 34 | 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) => ( |
11 | 37 | <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} |
14 | 40 | >
|
15 |
| - <Link href={`authors/${article.slug}`}> |
| 41 | + <Link href={`/authors/${author.slug}`}> |
16 | 42 | <Image
|
17 | 43 | 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} |
20 | 46 | width={150}
|
21 | 47 | height={150}
|
22 | 48 | />
|
23 | 49 | </Link>
|
24 | 50 | <article>
|
25 | 51 | <p className="heading3-title mb-4">
|
26 |
| - <Link href={`/authors/${article.slug}`}>{article.author}</Link> |
| 52 | + <Link href={`/authors/${author.slug}`}>{author.name}</Link> |
27 | 53 | </p>
|
28 | 54 | <div className="flex gap-8">
|
29 | 55 | <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> |
32 | 58 | </span>
|
33 | 59 | <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> |
36 | 62 | </span>
|
37 | 63 | </div>
|
38 | 64 | </article>
|
|
0 commit comments