Skip to content

Commit

Permalink
Merge pull request #175 from bryanlundberg/best-time-animations
Browse files Browse the repository at this point in the history
Add personal best time animations / alerts
  • Loading branch information
bryanlundberg authored Nov 19, 2023
2 parents 3397362 + acf8e7b commit b047de9
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 17 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"pretty-ms": "^8.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dom-confetti": "^0.2.0",
"recharts": "^2.8.0",
"scrambow": "^1.8.1",
"sharp": "0.32.6",
Expand Down
2 changes: 1 addition & 1 deletion src/components/PreloadSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function PreloadSettings({
return (
<>
<div className={`${theme}`}>
<div className="flex flex-col justify-between max-h-screen min-h-screen gap-2 select-none light:bg-neutral-50 light:text-zinc-950 dark:bg-zinc-950 dark:text-slate-50">
<div className="flex flex-col justify-between max-h-screen min-h-screen gap-2 select-none light:bg-neutral-50 light:text-zinc-950 dark:bg-zinc-950 dark:text-slate-50 overflow-hidden">
{children} <>{!isSolving && <Navbar />}</>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PlusIcon from "@/icons/PlusIcon";
import SelectOptions from "@/icons/SelectOptions";
import { useEffect, useRef, useState } from "react";
import { useRef, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { Categories } from "@/interfaces/Categories";
Expand Down Expand Up @@ -135,7 +135,8 @@ function Option({
cubeId: string;
handleClose: () => void;
}) {
const { selectedCube, setSelectedCube, setNewScramble } = useTimerStore();
const { selectedCube, setSelectedCube, setNewScramble, setLastSolve } =
useTimerStore();
const { settings } = useSettingsModalStore();

const variation: Record<Themes, string> = {
Expand All @@ -156,6 +157,7 @@ function Option({
if (cube) {
setSelectedCube(cube);
setNewScramble(cube);
setLastSolve(null);
}
}
handleClose();
Expand Down
2 changes: 1 addition & 1 deletion src/components/timer/OverviewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function OverviewPanel() {
const { session } = useTimerStatistics();

return (
<div className="flex flex-col justify-center w-full h-full">
<div className="flex flex-col justify-center w-full h-full gap-1">
{settings.features.sessionStats.status ? (
<>
<div className="font-medium">
Expand Down
54 changes: 44 additions & 10 deletions src/components/timer/StatisticsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,58 @@ import { useTimerStatistics } from "@/hooks/useTimerStatistics";

export default function StatisticsPanel() {
const { settings } = useSettingsModalStore();
const { session } = useTimerStatistics();
const { global, session } = useTimerStatistics();
const bgRecord = "bg-yellow-500";

return (
<>
<div className="flex flex-col justify-center w-full h-full">
<div className="flex flex-col justify-center w-full h-full gap-1">
{settings.features.sessionStats.status ? (
<>
<div className="font-medium text-right">
Ao5: {session.ao5 === 0 ? "--" : formatTime(session.ao5)}
<div className="flex justify-end w-full font-medium text-right">
<div
className={`w-fit px-[5px] rounded-md ${
global.ao5 !== 0 && global.ao5 === session.ao5 ? bgRecord : ""
}`}
>
Ao5: {session.ao5 === 0 ? "--" : formatTime(session.ao5)}
</div>
</div>
<div className="font-medium text-right">
Ao12: {session.ao12 === 0 ? "--" : formatTime(session.ao12)}
<div className="flex justify-end w-full font-medium text-right">
<div
className={`w-fit px-[5px] rounded-md ${
global.ao12 !== 0 && global.ao12 === session.ao12
? bgRecord
: ""
}`}
>
Ao12:{" "}
{global.ao12 !== 0 && session.ao12 === 0
? "--"
: formatTime(session.ao12)}
</div>
</div>
<div className="font-medium text-right">
Ao50: {session.ao50 === 0 ? "--" : formatTime(session.ao50)}
<div className="flex justify-end w-full font-medium text-right">
<div
className={`w-fit px-[5px] rounded-md ${
global.ao50 !== 0 && global.ao50 === session.ao50
? bgRecord
: ""
}`}
>
Ao50: {session.ao50 === 0 ? "--" : formatTime(session.ao50)}
</div>
</div>
<div className="font-medium text-right">
Ao100: {session.ao100 === 0 ? "--" : formatTime(session.ao100)}
<div className="flex justify-end w-full font-medium text-right">
<div
className={`w-fit px-[5px] rounded-md ${
global.ao100 !== 0 && global.ao100 === session.ao100
? bgRecord
: ""
}`}
>
Ao100: {session.ao100 === 0 ? "--" : formatTime(session.ao100)}
</div>
</div>
</>
) : null}
Expand Down
23 changes: 22 additions & 1 deletion src/components/timer/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useSettingsModalStore } from "@/store/SettingsModalStore";
import formatTime from "@/lib/formatTime";
import translation from "@/translations/global.json";
import useTimer from "@/hooks/useTimer";
import Confetti from "react-dom-confetti";
import { useTimerStatistics } from "@/hooks/useTimerStatistics";

const timerStatusClasses = {
idle: "light:text-neutral-900 dark:text-white",
Expand All @@ -12,12 +14,27 @@ const timerStatusClasses = {
ready: "text-emerald-400",
};

const config: any = {
angle: 90,
spread: 180,
startVelocity: 40,
elementCount: 70,
dragFriction: 0.12,
duration: 5000,
stagger: 3,
width: "10px",
height: "10px",
perspective: "500px",
colors: ["#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"],
};

export default function Timer() {
const { lang, settings } = useSettingsModalStore();
const { selectedCube, isSolving, lastSolve } = useTimerStore();
const { timerStatus, hideWhileSolving, solvingTime } = useTimer();
const { global } = useTimerStatistics();

if (selectedCube === null) return;
if (selectedCube === null) return <></>;

return (
<>
Expand All @@ -38,6 +55,10 @@ export default function Timer() {
)}
</div>
)}
<Confetti
active={global.best === lastSolve?.time && !isSolving}
config={config}
/>
{lastSolve &&
settings.features.quickActionButtons.status &&
timerStatus === "idle" && <SolveOptions solve={lastSolve} />}
Expand Down
12 changes: 10 additions & 2 deletions src/store/timerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ export const useTimerStore = create<TimerStore>((set) => ({
setSelectedCube: (cube: Cube | null) => {
set((state: any) => {
if (!cube) {
return { ...state, event: null, selectedCube: null };
return {
...state,
event: null,
selectedCube: null,
};
}

const selectedEvent = cubeCollection.find(
(item) => item.name === cube.category
);
return { ...state, event: selectedEvent?.event, selectedCube: cube };
return {
...state,
event: selectedEvent?.event,
selectedCube: cube,
};
});
},
setLastSolve: (solve: Solve | null) => {
Expand Down

0 comments on commit b047de9

Please sign in to comment.