Skip to content

Commit c30149e

Browse files
committed
WIP: type issue fixes
1 parent 0ea0891 commit c30149e

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

src/app/[category]/[subcategory]/[article]/page.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// import ArticleCard from "@/app/components/Articles/ArticleCard";
21
import { API_ENDPOINTS } from "@/config/endpoints";
32
import { getData } from "@/lib/helpers/dataFetchHelper";
43
import { ApiResponse, Article } from "@/types/CommonTypes";
@@ -8,16 +7,14 @@ import Link from "next/link";
87
export default async function Page({
98
params,
109
}: {
11-
params: { article: string; category: string; subcategory: string };
10+
params: Promise<{ article: string; category: string; subcategory: string }>;
1211
}) {
13-
const { category, subcategory } = await params;
14-
15-
const articleSlug = (await params).article;
12+
const { article, category, subcategory } = await params;
1613

1714
const response: ApiResponse<Article> = await getData(
18-
`${API_ENDPOINTS.ARTICLES}?filters[slug][$eq]=${articleSlug}`
15+
`${API_ENDPOINTS.ARTICLES}?filters[slug][$eq]=${article}`
1916
);
20-
const [{ title, publishedAt, description }] = response.data; // select first object in array, and destructure properties
17+
const [{ title, publishedAt, description }] = response.data;
2118

2219
const publishedDate = new Date(publishedAt).toLocaleDateString("en-US", {
2320
year: "numeric",
@@ -40,8 +37,7 @@ export default async function Page({
4037
<li>
4138
<Link
4239
href={`/${category}/${subcategory}`}
43-
className="hover:text-blue-600"
44-
>
40+
className="hover:text-blue-600">
4541
{subcategory}
4642
</Link>
4743
</li>
@@ -65,15 +61,13 @@ export default async function Page({
6561
</p>
6662
<button
6763
className=" flex items-center gap-2 text-white text-lg px-3 py-1 rounded-md shadow hover:brightness-110 transition"
68-
style={{ backgroundColor: "#2F7CC4" }}
69-
>
64+
style={{ backgroundColor: "#2F7CC4" }}>
7065
English
7166
<svg
7267
xmlns="http://www.w3.org/2000/svg"
7368
viewBox="0 0 24 24"
7469
fill="currentColor"
75-
className="size-6"
76-
>
70+
className="size-6">
7771
<path
7872
fillRule="evenodd"
7973
d="M12.53 16.28a.75.75 0 0 1-1.06 0l-7.5-7.5a.75.75 0 0 1 1.06-1.06L12 14.69l6.97-6.97a.75.75 0 1 1 1.06 1.06l-7.5 7.5Z"
@@ -103,15 +97,13 @@ export default async function Page({
10397
</h1>
10498
<button
10599
className=" flex gap-2 text-white text-lg px-8 py-3 rounded-md shadow hover:brightness-110 transition"
106-
style={{ backgroundColor: "#2F7CC4" }}
107-
>
100+
style={{ backgroundColor: "#2F7CC4" }}>
108101
Download PDF
109102
<svg
110103
xmlns="http://www.w3.org/2000/svg"
111104
viewBox="0 0 24 24"
112105
fill="currentColor"
113-
className="size-6"
114-
>
106+
className="size-6">
115107
<path
116108
fillRule="evenodd"
117109
d="M12 2.25a.75.75 0 0 1 .75.75v11.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 1 1 1.06-1.06l3.22 3.22V3a.75.75 0 0 1 .75-.75Zm-9 13.5a.75.75 0 0 1 .75.75v2.25a1.5 1.5 0 0 0 1.5 1.5h13.5a1.5 1.5 0 0 0 1.5-1.5V16.5a.75.75 0 0 1 1.5 0v2.25a3 3 0 0 1-3 3H5.25a3 3 0 0 1-3-3V16.5a.75.75 0 0 1 .75-.75Z"

src/app/[category]/[subcategory]/page.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import { ApiResponse, SubcategoryType } from "@/types/CommonTypes";
66
export default async function Page({
77
params,
88
}: {
9-
params: { category: string; subcategory: string };
9+
params: Promise<{ category: string; subcategory: string }>;
1010
}) {
1111
const response: ApiResponse<SubcategoryType> = await getData(
12-
`${API_ENDPOINTS.SUBCATEGORIES}?filters[slug][$eq]=${params.subcategory}&populate=articles`
12+
`${API_ENDPOINTS.SUBCATEGORIES}?filters[slug][$eq]=${
13+
(
14+
await params
15+
).subcategory
16+
}&populate=articles`
1317
);
1418

1519
const [{ name, subtitle, articles }] = response.data;
@@ -20,8 +24,7 @@ export default async function Page({
2024
id: article.id,
2125
title: article.title,
2226
description: article.description,
23-
content: article.content || "No content available", // Matches the expected `content` field
24-
imageUrl: article.image?.url || "/placeholder.png", // Matches the expected `imageUrl` field
27+
imageUrl: article?.thumbnailImage?.url, // Matches the expected `imageUrl` field
2528
slug: article.slug,
2629
}));
2730

@@ -34,8 +37,8 @@ export default async function Page({
3437

3538
<ArticleCard
3639
articles={transformedArticles}
37-
categorySlug={params.category}
38-
subcategorySlug={params.subcategory}
40+
categorySlug={(await params).category}
41+
subcategorySlug={(await params).subcategory}
3942
/>
4043
</>
4144
);

src/app/[category]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SubCategories from "../components/Subcategories/Subcategories";
66
export default async function Page({
77
params,
88
}: {
9-
params: { category: string };
9+
params: Promise<{ category: string }>;
1010
}) {
1111
const categorySlug = (await params).category;
1212
const response: ApiResponse<Category> = await getData(

src/app/components/Articles/ArticleCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ interface ArticleCardProps {
88
description: string;
99
id: number;
1010
title: string;
11-
content: string;
1211
imageUrl: string;
1312
slug: string;
1413
}>;

src/types/CommonTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export interface Article {
6363
category: string;
6464
subcategory: string;
6565
thumbnailImage: ImageType;
66+
publishedAt: string;
6667
}
6768

6869
export interface Subcategory {

0 commit comments

Comments
 (0)