From 0e7b36c2d443306325f17bb8850f5bb6176202bf Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Fri, 3 Jun 2022 19:04:53 +0300 Subject: initial --- src/components/Timers.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/components/Timers.js (limited to 'src/components/Timers.js') diff --git a/src/components/Timers.js b/src/components/Timers.js new file mode 100644 index 0000000..10b2557 --- /dev/null +++ b/src/components/Timers.js @@ -0,0 +1,41 @@ +import Timer from "./Timer"; + +const Timers = ({ items, setTimers }) => { + const setTime = (idx, time) => { + setTimers(items.map((t, id) => id !== idx ? t : { ...t, time: time, initialTime: time })); + }; + const initialTimer = (idx) => { + setTimers(items.map((t, id) => id !== idx ? t : { ...t, started: true, time: t.initialTime, startedAt: (new Date()).getTime() })); + }; + const stopTimer = (idx) => { + setTimers(items.map((t, id) => id !== idx ? t : { ...t, started: false })); + }; + const setTimerName = (idx, name) => { + setTimers(items.map((t, id) => id !== idx ? t : { ...t, name })); + }; + const deleteTimer = (idx) => { + setTimers(items.filter((t, id) => id !== idx)); + }; + const moveTimer = (idx, offset) => { + [items[idx], items[idx + offset]] = [items[idx + offset], items[idx]]; + setTimers(items); + }; + return items.map((t, idx) => setTime(idx, time)} + start={() => initialTimer(idx)} + stop={() => stopTimer(idx)} + setName={(name) => setTimerName(idx, name)} + remove={() => deleteTimer(idx)} + moveTimer={(offset) => moveTimer(idx, offset)} + />); +} + +export default Timers; -- cgit v1.2.3