-
Notifications
You must be signed in to change notification settings - Fork 28k
/
Copy pathpage.tsx
68 lines (60 loc) · 1.64 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { notFound } from "next/navigation";
import { CacheStateWatcher } from "../cache-state-watcher";
import { Suspense } from "react";
import { RevalidateFrom } from "../revalidate-from";
import Link from "next/link";
type TimeData = {
unixtime: number;
datetime: string;
timezone: string;
};
const timeZones = ["cet", "gmt"];
export const revalidate = 500;
export async function generateStaticParams() {
return timeZones.map((timezone) => ({ timezone }));
}
export default async function Page({ params: { timezone } }) {
const data = await fetch(
`https://worldtimeapi.org/api/timezone/${timezone}`,
{
next: { tags: ["time-data"] },
},
);
if (!data.ok) {
notFound();
}
const timeData: TimeData = await data.json();
return (
<>
<header className="header">
{timeZones.map((timeZone) => (
<Link key={timeZone} className="link" href={`/${timeZone}`}>
{timeZone.toUpperCase()} Time
</Link>
))}
</header>
<main className="widget">
<div className="pre-rendered-at">
{timeData.timezone} Time {timeData.datetime}
</div>
<Suspense fallback={null}>
<CacheStateWatcher
revalidateAfter={revalidate * 1000}
time={timeData.unixtime * 1000}
/>
</Suspense>
<RevalidateFrom />
</main>
<footer className="footer">
<Link
href={process.env.NEXT_PUBLIC_REDIS_INSIGHT_URL}
className="link"
target="_blank"
rel="noopener noreferrer"
>
View RedisInsight ↪
</Link>
</footer>
</>
);
}