Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewinci authored and sfogfar committed Jul 17, 2024
1 parent a87d6d1 commit 15bac86
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"env": {
"environment": "sandbox"
}
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["Automerge"]
}
Binary file added src/app/assets/cuckoo-clock.mp3
Binary file not shown.
26 changes: 18 additions & 8 deletions src/app/components/timer.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { Button, Group, Menu, Text } from "@mantine/core";
import { IconBellRinging, IconClock } from "@tabler/icons";
import { useEffect, useState } from "react";
import sound from "../assets/cuckoo-clock.mp3";
import * as State from "../state";
import { Button, Group, Menu, Text } from "@mantine/core";
import { IconBellRinging, IconClock } from "@tabler/icons-react";

const audio = new Audio(sound);

export const Timer = () => {
const onTimerSet = (seconds: number) => State.startTimer(seconds);
const settings = () => State.getAppState().timer;

const reset = () => {
State.resetTimer();
setTimeLeft(undefined);
};

const calculateTimeLeft = () => {
const timeLeft = Math.floor(
((settings()?.duration ?? 0) * 1000 -
(new Date().getTime() - (settings()?.start ?? 0))) /
1000,
);
if (settings() === null) {
if (settings() === null || settings() === undefined) {
return undefined;
} else if (timeLeft <= 0) {
if (timeLeft >= -1 && timeLeft <= 0) {
audio.play();
setTimeout(() => audio.pause(), 6000);
}
reset();
return 0;
} else {
return timeLeft;
Expand All @@ -33,11 +47,6 @@ export const Timer = () => {
return () => clearInterval(interval);
});

const reset = () => {
State.resetTimer();
setTimeLeft(undefined);
};

return (
<Menu shadow="md" width={200}>
<Menu.Target>
Expand Down Expand Up @@ -68,6 +77,7 @@ export const Timer = () => {
)}
{(timeLeft === 0 || timeLeft === undefined) && (
<Menu.Dropdown>
<Menu.Item onClick={() => onTimerSet?.(10)}>10 seconds</Menu.Item>
<Menu.Item onClick={() => onTimerSet?.(120)}>2 minutes</Menu.Item>
<Menu.Item onClick={() => onTimerSet?.(5 * 60)}>5 minutes</Menu.Item>
<Menu.Item onClick={() => onTimerSet?.(10 * 60)}>
Expand Down

0 comments on commit 15bac86

Please sign in to comment.