Skip to content

Commit d54d976

Browse files
committed
fix: fixing cache issues
1 parent 693c478 commit d54d976

File tree

2 files changed

+114
-2
lines changed

2 files changed

+114
-2
lines changed

app/api/timetable/route.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { AllResponse } from "@/types/Response";
21
import type { Schedule, ScheduleSlot } from "@/types/Timetable";
32
import { ImageResponse } from "next/og";
43
import { Time, timeConvert } from "@/utils/Times";
@@ -42,7 +41,7 @@ export async function GET() {
4241
new URL("../../../public/fonts/Geist.ttf", import.meta.url),
4342
).then((res) => res.arrayBuffer());
4443

45-
return new ImageResponse(
44+
const response = new ImageResponse(
4645
<section
4746
style={{
4847
height: "100%",
@@ -72,6 +71,15 @@ export async function GET() {
7271
],
7372
},
7473
);
74+
75+
return new Response(await response.arrayBuffer(), {
76+
headers: {
77+
'Content-Type': 'image/png',
78+
'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate',
79+
'Pragma': 'no-cache',
80+
'Expires': '0',
81+
},
82+
});
7583
}
7684
function TimeArr() {
7785
return (

app/view/page.tsx

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { fetchUserData } from '@/hooks/fetchUserData';
2+
import { type Schedule, type ScheduleSlot } from '@/types/Timetable';
3+
import { Time, timeConvert } from '@/utils/Times';
4+
import React from 'react'
5+
6+
export default async function ViewAll() {
7+
const {timetable, ophour} = await fetchUserData();
8+
9+
const ophours = ophour?.split(",");
10+
if (ophours?.[0]) {
11+
for (const ophour of ophours) {
12+
const [day, hour] = ophour.split("-");
13+
const dayIndex = Number.parseInt(day.replace("D", "")) - 1;
14+
const hourIndex = Number.parseInt(hour.replace("H", "")) - 1;
15+
16+
const slot = timetable.schedule[dayIndex]?.table[hourIndex];
17+
if (slot) slot.isOptional = true;
18+
}
19+
}
20+
21+
22+
return (
23+
<main className='max-w-screen h-screen w-screen overflow-hidden flex items-center justify-center'>
24+
<div className='flex flex-col max-w-[1710px] w-full h-full aspect-[1710/700] relative'>
25+
<div className='absolute inset-0'>
26+
<TimeArr />
27+
<TimetableImage timetable={timetable.schedule} />
28+
</div>
29+
</div>
30+
</main>
31+
)
32+
}
33+
34+
function TimeArr() {
35+
return (
36+
<div className="flex flex-row justify-between w-full px-12 h-[50px]">
37+
{Time.start.map((start, index) => (
38+
<div
39+
className="flex flex-col items-center justify-center"
40+
key={index}
41+
>
42+
<p className="text-white text-lg opacity-70">
43+
{timeConvert(start)} - {timeConvert(Time.end[index])}
44+
</p>
45+
</div>
46+
))}
47+
</div>
48+
);
49+
}
50+
51+
function TimetableImage({ timetable }: { timetable: Schedule[] }) {
52+
return (
53+
<div
54+
className="grid grid-rows-5"
55+
>
56+
{timetable.map((item, index) => (
57+
<ImageGenerator timetable={item} key={index} />
58+
))}
59+
</div>
60+
);
61+
}
62+
63+
function ImageGenerator({ timetable }: { timetable: Schedule }) {
64+
const theoryPosition = timetable?.table
65+
?.slice(0, 5)
66+
.some((item) => item?.courseType === "Theory")
67+
? 0
68+
: 1;
69+
70+
return (
71+
<div className="h-full grid grid-cols-2">
72+
<div
73+
className={`${theoryPosition === 0 ? "bg-[#F2D869]" : "bg-[#69E069]"} h-full grid grid-cols-5`}
74+
>
75+
{timetable?.table?.slice(0, 5).map((item, index) => (
76+
<TableCell key={index} cell={item} />
77+
))}
78+
</div>
79+
<div
80+
className={`${theoryPosition === 0 ? "bg-[#69E069]" : "bg-[#F2D869]"} h-full grid grid-cols-5`}
81+
>
82+
{timetable?.table?.slice(5, 10).map((item, index) => (
83+
<TableCell key={index} cell={item} />
84+
))}
85+
</div>
86+
</div>
87+
);
88+
}
89+
90+
function TableCell({ cell }: { cell: ScheduleSlot | null }) {
91+
return (
92+
<div
93+
className={`border-2 flex h-[130px] flex-col text-black relative justify-between items-start px-3 py-2 ${!cell ? "bg-black/80" : cell.isOptional ? "bg-black/40" : ""} border-black/60 w-full`}
94+
>
95+
<p className="text-base font-semibold text-left mr-3">
96+
{cell?.name.split(":")[0]}
97+
</p>
98+
<div className="flex items-end justify-between w-full opacity-60">
99+
<p className="text-sm font-semibold">{cell?.roomNo}</p>
100+
{cell?.isOptional && <p className="text-sm font-semibold">(Optional)</p>}
101+
</div>
102+
</div>
103+
);
104+
}

0 commit comments

Comments
 (0)