aboutsummaryrefslogtreecommitdiff
path: root/src/components/Timers.js
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-06-03 19:04:53 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-06-03 19:04:53 +0300
commit0e7b36c2d443306325f17bb8850f5bb6176202bf (patch)
tree86629d4fe05d73f2d77dad423cc37d5a612430f3 /src/components/Timers.js
parent15d75cdc37e1459f7d11d004005d4305a6377ffd (diff)
initialHEADmaster
Diffstat (limited to 'src/components/Timers.js')
-rw-r--r--src/components/Timers.js41
1 files changed, 41 insertions, 0 deletions
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) => <Timer
+ key={`item-${idx}`}
+ index={idx}
+ first={idx === 0}
+ last={idx === (items.length-1)}
+ name={t.name}
+ started={t.started}
+ time={t.time || 0}
+ initialTime={t.initialTime || 0}
+ setTime={(time) => 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;