diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-03-06 02:18:40 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-03-06 02:18:40 +0900 |
| commit | 46f9ba5d8c295454381655e6ec02ad3cf8bd79db (patch) | |
| tree | c54719cb129ee05f96c4898219588062f71daa36 /frontend/app/states/watch.ts | |
| parent | 27f509ccf4fbfeaa1bc2580ae2251461dc44ebfa (diff) | |
| download | phperkaigi-2026-albatross-46f9ba5d8c295454381655e6ec02ad3cf8bd79db.tar.gz phperkaigi-2026-albatross-46f9ba5d8c295454381655e6ec02ad3cf8bd79db.tar.zst phperkaigi-2026-albatross-46f9ba5d8c295454381655e6ec02ad3cf8bd79db.zip | |
style: switch from tab to space indentation in frontend and worker/php
Update biome.json indentStyle from "tab" to "space" and reformat all
files in both workspaces.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'frontend/app/states/watch.ts')
| -rw-r--r-- | frontend/app/states/watch.ts | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/frontend/app/states/watch.ts b/frontend/app/states/watch.ts index 50fa425..3431b6d 100644 --- a/frontend/app/states/watch.ts +++ b/frontend/app/states/watch.ts @@ -4,136 +4,136 @@ import type { SupportedLanguage } from "../types/SupportedLanguage"; const gameStartedAtAtom = atom<number | null>(null); export const setGameStartedAtAtom = atom(null, (_, set, value: number | null) => - set(gameStartedAtAtom, value), + set(gameStartedAtAtom, value), ); export type GameStateKind = - | "loading" - | "waiting" - | "starting" - | "gaming" - | "finished"; + | "loading" + | "waiting" + | "starting" + | "gaming" + | "finished"; type LatestGameState = components["schemas"]["LatestGameState"]; type RankingEntry = components["schemas"]["RankingEntry"]; export const gameStateKindAtom = atom<GameStateKind>((get) => { - const now = get(currentTimestampAtom); - if (!now) { - return "loading"; - } - const startedAt = get(gameStartedAtAtom); - if (!startedAt) { - return "waiting"; - } - const durationSeconds = get(durationSecondsAtom); - const finishedAt = startedAt + durationSeconds; - if (now < startedAt) { - return "starting"; - } else if (now < finishedAt) { - return "gaming"; - } else { - return "finished"; - } + const now = get(currentTimestampAtom); + if (!now) { + return "loading"; + } + const startedAt = get(gameStartedAtAtom); + if (!startedAt) { + return "waiting"; + } + const durationSeconds = get(durationSecondsAtom); + const finishedAt = startedAt + durationSeconds; + if (now < startedAt) { + return "starting"; + } else if (now < finishedAt) { + return "gaming"; + } else { + return "finished"; + } }); const currentTimestampAtom = atom<number | null>(null); export const setCurrentTimestampAtom = atom(null, (_, set) => - set(currentTimestampAtom, Math.floor(Date.now() / 1000)), + set(currentTimestampAtom, Math.floor(Date.now() / 1000)), ); const durationSecondsAtom = atom<number>(0); export const setDurationSecondsAtom = atom(null, (_, set, value: number) => - set(durationSecondsAtom, value), + set(durationSecondsAtom, value), ); export const startingLeftTimeSecondsAtom = atom<number | null>((get) => { - const startedAt = get(gameStartedAtAtom); - if (startedAt === null) { - return null; - } - const currentTimestamp = get(currentTimestampAtom); - if (currentTimestamp === null) { - return null; - } - return Math.max(0, startedAt - currentTimestamp); + const startedAt = get(gameStartedAtAtom); + if (startedAt === null) { + return null; + } + const currentTimestamp = get(currentTimestampAtom); + if (currentTimestamp === null) { + return null; + } + return Math.max(0, startedAt - currentTimestamp); }); export const gamingLeftTimeSecondsAtom = atom<number | null>((get) => { - const startedAt = get(gameStartedAtAtom); - if (startedAt === null) { - return null; - } - const durationSeconds = get(durationSecondsAtom); - const finishedAt = startedAt + durationSeconds; - const currentTimestamp = get(currentTimestampAtom); - if (currentTimestamp === null) { - return null; - } - return Math.min(durationSeconds, Math.max(0, finishedAt - currentTimestamp)); + const startedAt = get(gameStartedAtAtom); + if (startedAt === null) { + return null; + } + const durationSeconds = get(durationSecondsAtom); + const finishedAt = startedAt + durationSeconds; + const currentTimestamp = get(currentTimestampAtom); + if (currentTimestamp === null) { + return null; + } + return Math.min(durationSeconds, Math.max(0, finishedAt - currentTimestamp)); }); export const rankingAtom = atom<RankingEntry[]>([]); const rawLatestGameStatesAtom = atom<{ - [key: string]: LatestGameState | undefined; + [key: string]: LatestGameState | undefined; }>({}); export const latestGameStatesAtom = atom((get) => get(rawLatestGameStatesAtom)); export const setLatestGameStatesAtom = atom( - null, - (_, set, value: { [key: string]: LatestGameState | undefined }) => { - set(rawLatestGameStatesAtom, value); - }, + null, + (_, set, value: { [key: string]: LatestGameState | undefined }) => { + set(rawLatestGameStatesAtom, value); + }, ); function cleanCode(code: string, language: SupportedLanguage) { - if (language === "php") { - return code - .replace(/\s+/g, "") - .replace(/^<\?php/, "") - .replace(/^<\?/, "") - .replace(/\?>$/, ""); - } else { - return code.replace(/\s+/g, ""); - } + if (language === "php") { + return code + .replace(/\s+/g, "") + .replace(/^<\?php/, "") + .replace(/^<\?/, "") + .replace(/\?>$/, ""); + } else { + return code.replace(/\s+/g, ""); + } } export function calcCodeSize( - code: string, - language: SupportedLanguage, + code: string, + language: SupportedLanguage, ): number { - const trimmed = cleanCode(code, language); - const utf8Encoded = new TextEncoder().encode(trimmed); - return utf8Encoded.length; + const trimmed = cleanCode(code, language); + const utf8Encoded = new TextEncoder().encode(trimmed); + return utf8Encoded.length; } export type GameResultKind = "winA" | "winB" | "draw"; export function checkGameResultKind( - gameStateKind: GameStateKind, - stateA: LatestGameState | null, - stateB: LatestGameState | null, + gameStateKind: GameStateKind, + stateA: LatestGameState | null, + stateB: LatestGameState | null, ): GameResultKind | null { - if (gameStateKind !== "finished") { - return null; - } + if (gameStateKind !== "finished") { + return null; + } - const scoreA = stateA?.score; - const scoreB = stateB?.score; - if (scoreA == null && scoreB == null) { - return "draw"; - } - if (scoreA == null) { - return "winB"; - } - if (scoreB == null) { - return "winA"; - } - if (scoreA === scoreB) { - // If score is non-null, state and best_score_submitted_at should also be non-null. - const submittedAtA = stateA!.best_score_submitted_at!; - const submittedAtB = stateB!.best_score_submitted_at!; - return submittedAtA < submittedAtB ? "winA" : "winB"; - } else { - return scoreA < scoreB ? "winA" : "winB"; - } + const scoreA = stateA?.score; + const scoreB = stateB?.score; + if (scoreA == null && scoreB == null) { + return "draw"; + } + if (scoreA == null) { + return "winB"; + } + if (scoreB == null) { + return "winA"; + } + if (scoreA === scoreB) { + // If score is non-null, state and best_score_submitted_at should also be non-null. + const submittedAtA = stateA!.best_score_submitted_at!; + const submittedAtB = stateB!.best_score_submitted_at!; + return submittedAtA < submittedAtB ? "winA" : "winB"; + } else { + return scoreA < scoreB ? "winA" : "winB"; + } } |
