blob: 43d88eda10c188d6c6ce10e594685dd74706d821 (
plain) (
blame)
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
|
import { useEffect, useState } from "react";
import TwitchDataTable, {
type TwitchDataTableProp,
} from "../../components/SubscriberTable/TwitchDataTable";
import TitleBar from "../../components/TitleBar/TitleBar";
import Announcement from "../../components/Announcement";
import "../../app/globals.css";
function TwitchPage() {
const [twitchData, setTwitchData] = useState<TwitchDataTableProp | null>(null);
const [error, setError] = useState<string | null>(null);
const announcementText = process.env.NEXT_PUBLIC_ANNOUNCEMENT;
useEffect(() => {
async function fetchTwitchData() {
try {
const apiUrl = process.env.NEXT_PUBLIC_API_URL_TESTING;
const endpoint = "/api/twitch";
const headers = {
"Cache-Control": "no-cache",
};
const cacheOption = "no-cache";
const response = await fetch(`${apiUrl}${endpoint}`, {
headers: headers,
cache: cacheOption,
});
if (!response.ok) {
throw new Error(response.statusText);
}
const data = await response.json();
setTwitchData(data);
} catch (err) {
setError(err instanceof Error ? err.message : "An error occurred");
}
}
fetchTwitchData();
}, []);
return (
<>
<TitleBar title="PhaseTracker" backgroundColor="black" />
{announcementText && (
<Announcement
message={announcementText}
backgroundColor="#e0f7fa"
textColor="#006064"
/>
)}
{error ? (
<div>Error: {error}</div>
) : twitchData ? (
<TwitchDataTable {...twitchData} />
) : (
<div>Loading...</div>
)}
</>
);
}
export default TwitchPage;
|