From b0b04f645eb60cc231e4a986f413b839a0fdad1c Mon Sep 17 00:00:00 2001 From: Vyacheslav Date: Sat, 14 Jun 2025 19:16:46 +0500 Subject: [PATCH] save all changes to localStorage --- src/components/Timer/Timer.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/Timer/Timer.tsx b/src/components/Timer/Timer.tsx index 2b72149..5c45989 100644 --- a/src/components/Timer/Timer.tsx +++ b/src/components/Timer/Timer.tsx @@ -38,9 +38,14 @@ const Timer = (props: TimerProps) => { } }, [timeManager]) - const handlePause = () => timeManager.togglePause(); - const handleAdd = () => timeManager.addTime(1); - const handleSubstract = () => timeManager.subtractTime(1); + const handleUpdate = (updater: (manager: TimeManager) => void) => { + updater(timeManager); + localStorageManager.setItem(props.id, timeManager); + } + + const handlePause = () => handleUpdate(m => m.togglePause()); + const handleAdd = () => handleUpdate(m => m.addTime(1)); + const handleSubstraction = () => handleUpdate(m => m.subtractTime(1)); const handleRecreation = (minutes: number) => { const newTimeManager = new TimeManager(minutes) recreateTimeManager(newTimeManager); @@ -51,7 +56,7 @@ const Timer = (props: TimerProps) => {
-