Skip to content

Commit 4365bd1

Browse files
committed
Update to next16 and fix lint errors
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent 950f822 commit 4365bd1

File tree

8 files changed

+260
-171
lines changed

8 files changed

+260
-171
lines changed

components/Player.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,10 @@ function InternalPlayer({ data, children, starred, extraText, condensed }) {
3030
const t = useContext(TranslateContext);
3131
const [countdown, setCountown] = useState(0);
3232
useEffect(() => {
33-
const id = setInterval(
34-
() => setCountown((countdown) => countdown - 1),
35-
60000,
36-
);
37-
return () => {
38-
clearInterval(id);
39-
};
40-
}, []);
41-
// Makes sure that the countdown is up to date
42-
useEffect(() => {
43-
setCountown(
44-
data.game ? Math.ceil((data.game.gameStart - Date.now() / 1000) / 60) : 0,
45-
);
33+
const check = () => setCountown(data.game ? Math.ceil((data.game.gameStart - Date.now() / 1000) / 60) : 0);
34+
queueMicrotask(check);
35+
const id = setInterval(check, 10000);
36+
return () => clearInterval(id);
4637
}, [data]);
4738
const theme = useTheme();
4839
const dark = theme.palette.mode === "dark";

components/Prediction.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { NotifyContext, TranslateContext } from "#/Modules/context";
22
import { useContext, useEffect, useState } from "react";
33
import { TextField } from "@mui/material";
4+
5+
function GameEndHeader({ gameEnd }: { gameEnd: number }) {
6+
const t = useContext(TranslateContext);
7+
const [isPastGameEnd, setIsPastGameEnd] = useState(false);
8+
useEffect(() => {
9+
const check = () => setIsPastGameEnd(Date.now() / 1000 > gameEnd);
10+
queueMicrotask(check);
11+
const id = setInterval(check, 10000);
12+
return () => clearInterval(id);
13+
}, [gameEnd]);
14+
return <h4>{isPastGameEnd ? t("Final Scores") : t("Current Scores")}</h4>;
15+
}
416
export interface predictions {
517
home_team: string;
618
home_team_name: string | undefined;
@@ -63,18 +75,13 @@ export function Game({
6375
notify(t(await response.text()), response.ok ? "success" : "error");
6476
});
6577
}
66-
const [countdown, setCountown] = useState<number>(
67-
Math.ceil((gameStart - Date.now() / 1000) / 60),
68-
);
78+
const [countdown, setCountown] = useState<number>(0);
6979
useEffect(() => {
70-
const id = setInterval(
71-
() => setCountown((countdown) => countdown - 1),
72-
60000,
73-
);
74-
return () => {
75-
clearInterval(id);
76-
};
77-
}, []);
80+
const check = () => setCountown(Math.ceil((gameStart - Date.now() / 1000) / 60));
81+
queueMicrotask(check);
82+
const id = setInterval(check, 10000);
83+
return () => clearInterval(id);
84+
}, [gameStart]);
7885
const t = useContext(TranslateContext);
7986
const home_team_text = home_team_name || home_team;
8087
const away_team_text = away_team_name || away_team;
@@ -129,11 +136,7 @@ export function Game({
129136
</p>
130137
</>
131138
)}
132-
<h4>
133-
{Date.now() / 1000 > gameEnd
134-
? t("Final Scores")
135-
: t("Current Scores")}
136-
</h4>
139+
<GameEndHeader gameEnd={gameEnd} />
137140
<p>
138141
{home_score} - {away_score}
139142
</p>

eslint.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "node:path";
44
import { fileURLToPath } from "node:url";
55
import js from "@eslint/js";
66
import { FlatCompat } from "@eslint/eslintrc";
7+
import nextVitals from 'eslint-config-next/core-web-vitals';
78

89
const __filename = fileURLToPath(import.meta.url);
910
const __dirname = path.dirname(__filename);
@@ -32,8 +33,8 @@ export default [
3233
"next-env.d.ts",
3334
],
3435
},
36+
...nextVitals,
3537
...compat.extends(
36-
"next/core-web-vitals",
3738
"plugin:@typescript-eslint/recommended",
3839
),
3940
{

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
/// <reference path="./.next/types/routes.d.ts" />
3+
import "./.next/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

0 commit comments

Comments
 (0)