Skip to content

Commit 2d72377

Browse files
Merge pull request #212 from bryanlundberg/new-timer-logic
Reworked all logic from old timer making it easier to read and maintain, includes new feature "inspection".
2 parents 91418a6 + 87011ac commit 2d72377

File tree

7 files changed

+252
-149
lines changed

7 files changed

+252
-149
lines changed

src/components/PreloadSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function PreloadSettings({
1818
<div className={`${theme}`}>
1919
<div className="flex flex-col justify-between max-h-screen min-h-screen gap-2 overflow-hidden select-none light:bg-neutral-50 light:text-zinc-950 dark:bg-zinc-950 dark:text-slate-50">
2020
{children}{" "}
21-
<>{!isSolving && timerStatus !== "ready" ? <Navbar /> : null}</>
21+
<>{!isSolving && timerStatus === "IDLE" ? <Navbar /> : null}</>
2222
</div>
2323
</div>
2424
</>

src/components/timer/HeaderTimer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function HeaderTimer() {
1717
const { global } = useTimerStatistics();
1818
const { lastSolve } = useTimerStore();
1919

20-
if (isSolving || timerStatus === "ready") return null;
20+
if (isSolving || timerStatus !== "IDLE") return null;
2121
return (
2222
<div className="flex flex-col items-center justify-center gap-5 p-4">
2323
<div className="flex items-center gap-3">

src/components/timer/Timer.tsx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import { useTimerStatistics } from "@/hooks/useTimerStatistics";
99
import useDeviceMatch from "@/hooks/useDeviceMatch";
1010

1111
const timerStatusClasses = {
12-
idle: "light:text-neutral-900 dark:text-white",
13-
holdingKey: "light:text-pink-600 dark:text-pink-600",
14-
solving: "light:text-neutral-700 dark:text-slate-200",
15-
ready: "text-emerald-400",
12+
IDLE: "light:text-neutral-900 dark:text-white",
13+
HOLDING: "light:text-pink-600 dark:text-pink-600",
14+
SOLVING: "light:text-neutral-700 dark:text-slate-200",
15+
READY: "text-emerald-400",
16+
INSPECTING: "text-orange-500",
1617
};
1718

1819
const config: any = {
@@ -31,10 +32,12 @@ const config: any = {
3132

3233
export default function Timer() {
3334
const { lang, settings } = useSettingsModalStore();
34-
const { selectedCube, isSolving, lastSolve } = useTimerStore();
35-
const { timerStatus, hideWhileSolving, solvingTime } = useTimer();
35+
const { selectedCube, isSolving, lastSolve, timerStatus, solvingTime } =
36+
useTimerStore();
37+
const { inspectionTime } = useTimer();
3638
const { global } = useTimerStatistics();
3739
const { device } = useDeviceMatch();
40+
const hideWhileSolving = settings.features.hideWhileSolving.status;
3841

3942
return (
4043
selectedCube && (
@@ -50,16 +53,26 @@ export default function Timer() {
5053
{translation.timer["solving"][lang]}
5154
</span>
5255
) : (
53-
<div className="font-mono relative flex flex-col gap-1">
56+
<div className="relative flex flex-col gap-1 font-mono">
5457
<div className="flex items-end justify-center">
55-
<div className="text-6xl sm:text-7xl md:text-8xl lg:text-9xl">
56-
{formatTime(solvingTime).split(".")[0]}
57-
</div>
58-
<div className="text-5xl sm:text-6xl md:text-7xl lg:text-8xl">
59-
.{formatTime(solvingTime).split(".")[1]}
60-
</div>
58+
{inspectionTime !== 16000 ? (
59+
<>
60+
<div className="text-6xl sm:text-7xl md:text-8xl lg:text-9xl">
61+
{Math.trunc(inspectionTime)}
62+
</div>
63+
</>
64+
) : (
65+
<>
66+
<div className="text-6xl sm:text-7xl md:text-8xl lg:text-9xl">
67+
{formatTime(solvingTime).split(".")[0]}
68+
</div>
69+
<div className="text-5xl sm:text-6xl md:text-7xl lg:text-8xl">
70+
.{formatTime(solvingTime).split(".")[1]}
71+
</div>
72+
</>
73+
)}
6174
</div>
62-
{!lastSolve && timerStatus === "idle" ? (
75+
{!lastSolve && timerStatus === "IDLE" ? (
6376
<div className="text-xs text-center animate-pulse">
6477
{device === "Desktop"
6578
? `${translation.timer["space-to-start"][lang]}`
@@ -80,7 +93,7 @@ export default function Timer() {
8093
/>
8194
{lastSolve &&
8295
settings.features.quickActionButtons.status &&
83-
timerStatus === "idle" && <SolveOptions solve={lastSolve} />}
96+
timerStatus === "IDLE" && <SolveOptions solve={lastSolve} />}
8497
</div>
8598
</>
8699
)

src/components/timer/TimerWidgets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function TimerWidgets() {
1010
const { isSolving, timerStatus } = useTimerStore();
1111
const { lang, settings } = useSettingsModalStore();
1212
const { global, session } = useTimerStatistics();
13-
if (isSolving || timerStatus === "ready") return null;
13+
if (isSolving || timerStatus !== "IDLE") return null;
1414
return (
1515
<>
1616
<div className="flex flex-col gap-1" id="touch">

0 commit comments

Comments
 (0)