fixed no images problem and no cache in fetchCourses

This commit is contained in:
Philip Cheung 2024-11-05 23:06:48 +08:00
parent a00cd857f1
commit b6c5b15900
2 changed files with 41 additions and 19 deletions

View File

@ -47,12 +47,22 @@ const CoursesSilder = ({ courses }: { courses: CoursesProps[] }) => {
<div key={index} className=" bg-[#F6E8E9] h-auto pt-30 transition-all justify-items-center duration-20"> <div key={index} className=" bg-[#F6E8E9] h-auto pt-30 transition-all justify-items-center duration-20">
<div className="hidden lg:grid lg:grid-cols-2 w-full mb-28"> <div className="hidden lg:grid lg:grid-cols-2 w-full mb-28">
<div className="flex col-span-1 h-auto justify-self-end mr-20"> <div className="flex col-span-1 h-auto justify-self-end mr-20">
{course.images.length > 0 ? (
<img <img
src={`${process.env.NEXT_PUBLIC_IMAGE_URL}${course.images[0].image}`} src={`${process.env.NEXT_PUBLIC_IMAGE_URL}${course.images[0].image}`}
alt="Course Image" alt="Course Image"
className="w-[50vh] h-[70vh] object-cover object-center rounded-3xl shadow-md" className="w-[50vh] h-[70vh] object-cover object-center rounded-3xl shadow-md"
style={{ aspectRatio: '1 / 1' }} style={{ aspectRatio: '1 / 1' }}
/> />
) : (
<img
src={"/images/piano1.jpg"}
alt="Course Image"
className="w-[50vh] h-[70vh] object-cover object-center rounded-3xl shadow-md"
style={{ aspectRatio: '1 / 1' }}
/>
)}
</div> </div>
<div className="flex col-span-1 h-auto justify-start items-center ml-20"> <div className="flex col-span-1 h-auto justify-start items-center ml-20">
<div className="flex flex-col items-start w-[50vh]"> <div className="flex flex-col items-start w-[50vh]">
@ -76,11 +86,20 @@ const CoursesSilder = ({ courses }: { courses: CoursesProps[] }) => {
</div> </div>
<div className=" relative w-[50vh] h-[70vh] max-sm:w-[85vw] max-sm:h-[60vh] mt-20 mb-28 overflow-hidden rounded-3xl shadow-md sm:block md:block lg:hidden xl:hidden 2xl:hidden mx-auto"> <div className=" relative w-[50vh] h-[70vh] max-sm:w-[85vw] max-sm:h-[60vh] mt-20 mb-28 overflow-hidden rounded-3xl shadow-md sm:block md:block lg:hidden xl:hidden 2xl:hidden mx-auto">
{course.images.length > 0 ? (
<img <img
src={`${process.env.NEXT_PUBLIC_IMAGE_URL}${course.images[0].image}`} src={`${process.env.NEXT_PUBLIC_IMAGE_URL}${course.images[0].image}`}
alt="Course Image" alt="Course Image"
className="absolute inset-0 w-full h-full object-cover object-center " className="absolute inset-0 w-full h-full object-cover object-center "
/> />
) : (
<img
src={"/images/piano1.jpg"}
alt="Course Image"
className="absolute inset-0 w-full h-full object-cover object-center "
/>
)}
<div className="absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-50 text-white p-6"> <div className="absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-50 text-white p-6">
<p className="text-2xl text-center mb-4"> <p className="text-2xl text-center mb-4">
{course.title} {course.title}

View File

@ -92,7 +92,7 @@ export async function fetchCourses() {
console.log('Fetching from URL:', url); console.log('Fetching from URL:', url);
try { try {
const response = await fetch(url, { headers }); const response = await fetch(url, { headers, cache: 'no-store', next: { revalidate: 0 } });
const result = await response.json(); const result = await response.json();
@ -124,7 +124,10 @@ export async function fetchCourse(id: string) {
try { 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(); var result: CoursesProps = await response.json();