From 136772b355392f864c74d9933932785506460ede Mon Sep 17 00:00:00 2001 From: nzambello Date: Tue, 21 Dec 2021 17:44:12 +0100 Subject: [PATCH] refactor: fixes and styles --- package.json | 1 + src/App.css | 47 ++++++++++++++++++++++++++++++++---- src/App.tsx | 66 ++++++++++++++++++++++++++++++++++++++++++++------- src/index.css | 2 +- src/main.tsx | 13 +++++----- yarn.lock | 5 ++++ 6 files changed, 114 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index fd67eab..dc0b634 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test": "tsc" }, "dependencies": { + "@fontsource/fira-code": "^4.5.2", "classnames": "^2.3.1", "date-fns": "^2.27.0", "geolib": "^3.3.3", diff --git a/src/App.css b/src/App.css index 5f553ef..edb434d 100644 --- a/src/App.css +++ b/src/App.css @@ -37,15 +37,42 @@ } .App.alarm-set p { - font-size: 30vw; - font-weight: bold; color: coral; - opacity: 0.2; margin: 0; } -.App.alarm-set p:hover { + +.clock { + font-size: 27vw; + font-weight: bold; + display: block; + opacity: 0.2; + font-weight: 700; + font-family: 'Fira Code', monospace; + letter-spacing: -4px; +} +.clock:hover { opacity: 0.4; } +.App.alarm-playing .clock { + opacity: 1; + animation: blink 0.6s linear infinite; +} + +@keyframes blink { + 0% { + opacity: 1; + } + 100% { + opacity: 0.4; + } +} + +small { + display: inline-block; + font-family: 'Fira Code'; + margin-bottom: 2rem; + opacity: 0.3; +} .App-logo { height: 40vmin; @@ -103,3 +130,15 @@ h1 { .time-picker input:focus { outline: 1px solid currentColor; } + +.pa-4 { + padding: 1.5rem +} + +.ma-4 { + margin: 1.5rem; +} + +.ml-2 { + margin-left: 0.5rem; +} diff --git a/src/App.tsx b/src/App.tsx index 6e35d02..5aafb48 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import { getDistance } from "geolib"; import { format, parse, differenceInMilliseconds, isMatch } from "date-fns"; import useStayAwake from "use-stay-awake"; -import { TextField, Button } from "ui-neumorphism"; +import { TextField, Button, Dialog, Card } from "ui-neumorphism"; import { overrideThemeVariables } from "ui-neumorphism"; import "ui-neumorphism/dist/index.css"; @@ -60,6 +60,10 @@ function App() { useEffect(() => { if (alarmSet && distance > stopDistance) { resetAlarm(); + } else { + setHasWalked(false); + setAlarmPlaying(true); + audioRef.current?.play(); } }, [distance, alarmSet]); @@ -68,6 +72,7 @@ function App() { setAlarmSet(false); setAlarmPlaying(false); setAlarm(null); + audioRef.current?.pause(); if (device.canSleep) { device.allowSleeping(); } @@ -118,11 +123,26 @@ function App() { ? "alarm-set" : ""; + const [clock, setClock] = useState(format(new Date(), "HH:mm")); + useEffect(() => { + const interval = setInterval(() => { + if (!clock.includes(":") || alarmPlaying) + setClock(format(new Date(), "HH:mm")); + else setClock(format(new Date(), "HH mm")); + }, 1000); + return () => clearInterval(interval); + }); + + const [showResetModal, setResetModal] = useState(false); + return (
{alarmSet && alarm ? ( -

{format(alarm, "HH:mm")}

+

+ {clock} + Alarm: {format(alarm, "HH:mm")} +

) : ( <>

Alarm clock

@@ -183,16 +203,44 @@ function App() { )} {alarmSet && ( - )} + setResetModal(false)} + > + + Are you sure?

+ + +
+
+ {alarmPlaying && distance && ( +

+ Distance: {distance.toFixed(2)} / {stopDistance} meters +

+ )}