Skip to content

Commit cac4c81

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

File tree

8 files changed

+231
-164
lines changed

8 files changed

+231
-164
lines changed

components/Player.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,15 @@ 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 = () =>
34+
setCountown(
35+
data.game
36+
? Math.ceil((data.game.gameStart - Date.now() / 1000) / 60)
37+
: 0,
38+
);
39+
queueMicrotask(check);
40+
const id = setInterval(check, 10000);
41+
return () => clearInterval(id);
4642
}, [data]);
4743
const theme = useTheme();
4844
const dark = theme.palette.mode === "dark";

components/Prediction.tsx

Lines changed: 20 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,14 @@ 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 = () =>
81+
setCountown(Math.ceil((gameStart - Date.now() / 1000) / 60));
82+
queueMicrotask(check);
83+
const id = setInterval(check, 10000);
84+
return () => clearInterval(id);
85+
}, [gameStart]);
7886
const t = useContext(TranslateContext);
7987
const home_team_text = home_team_name || home_team;
8088
const away_team_text = away_team_name || away_team;
@@ -129,11 +137,7 @@ export function Game({
129137
</p>
130138
</>
131139
)}
132-
<h4>
133-
{Date.now() / 1000 > gameEnd
134-
? t("Final Scores")
135-
: t("Current Scores")}
136-
</h4>
140+
<GameEndHeader gameEnd={gameEnd} />
137141
<p>
138142
{home_score} - {away_score}
139143
</p>

eslint.config.mjs

Lines changed: 3 additions & 4 deletions
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,10 +33,8 @@ export default [
3233
"next-env.d.ts",
3334
],
3435
},
35-
...compat.extends(
36-
"next/core-web-vitals",
37-
"plugin:@typescript-eslint/recommended",
38-
),
36+
...nextVitals,
37+
...compat.extends("plugin:@typescript-eslint/recommended"),
3938
{
4039
plugins: {
4140
"@typescript-eslint": typescriptEslint,

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)