From b6c5b1590010a1856b067ed07b885d18514de652 Mon Sep 17 00:00:00 2001 From: Philip Cheung Date: Tue, 5 Nov 2024 23:06:48 +0800 Subject: [PATCH] fixed no images problem and no cache in fetchCourses --- components/CoursesSilder.tsx | 53 ++++++++++++++++++++++++------------ utils/index.ts | 7 +++-- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/components/CoursesSilder.tsx b/components/CoursesSilder.tsx index 4d617e0..6f6c7db 100644 --- a/components/CoursesSilder.tsx +++ b/components/CoursesSilder.tsx @@ -47,12 +47,22 @@ const CoursesSilder = ({ courses }: { courses: CoursesProps[] }) => {
- Course Image + {course.images.length > 0 ? ( + Course Image + ) : ( + Course Image + )} +
@@ -76,11 +86,20 @@ const CoursesSilder = ({ courses }: { courses: CoursesProps[] }) => {
- Course Image + {course.images.length > 0 ? ( + Course Image + ) : ( + Course Image + )} +

{course.title} @@ -89,12 +108,12 @@ const CoursesSilder = ({ courses }: { courses: CoursesProps[] }) => { {course.sort_description}

- {"了解更多"} - + href={`/courses/${course.id}`} + className="flex items-center justify-center rounded-full bg-white h-12 w-28 text-sm text-black shadow-md shadow-gray-400/20 transition-all hover:shadow-lg hover:shadow-gray-500/40" + data-ripple-light="true" + > + {"了解更多"} +
diff --git a/utils/index.ts b/utils/index.ts index bd86b3b..330506e 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -92,7 +92,7 @@ export async function fetchCourses() { console.log('Fetching from URL:', url); try { - const response = await fetch(url, { headers }); + const response = await fetch(url, { headers, cache: 'no-store', next: { revalidate: 0 } }); const result = await response.json(); @@ -124,7 +124,10 @@ export async function fetchCourse(id: string) { try { - const response = await fetch(url, { headers }); + const response = await fetch(url, { + headers, cache: 'no-store', + next: { revalidate: 0 } + }); var result: CoursesProps = await response.json();