mirror of
https://github.com/sheptikhinv/timers.git
synced 2026-02-07 07:41:36 +05:00
save all changes to localStorage
This commit is contained in:
parent
bd5b71f3fb
commit
b0b04f645e
1 changed files with 9 additions and 4 deletions
|
|
@ -38,9 +38,14 @@ const Timer = (props: TimerProps) => {
|
||||||
}
|
}
|
||||||
}, [timeManager])
|
}, [timeManager])
|
||||||
|
|
||||||
const handlePause = () => timeManager.togglePause();
|
const handleUpdate = (updater: (manager: TimeManager) => void) => {
|
||||||
const handleAdd = () => timeManager.addTime(1);
|
updater(timeManager);
|
||||||
const handleSubstract = () => timeManager.subtractTime(1);
|
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 handleRecreation = (minutes: number) => {
|
||||||
const newTimeManager = new TimeManager(minutes)
|
const newTimeManager = new TimeManager(minutes)
|
||||||
recreateTimeManager(newTimeManager);
|
recreateTimeManager(newTimeManager);
|
||||||
|
|
@ -51,7 +56,7 @@ const Timer = (props: TimerProps) => {
|
||||||
<div className={styles.timer_container}>
|
<div className={styles.timer_container}>
|
||||||
<div className={styles.top_buttons}>
|
<div className={styles.top_buttons}>
|
||||||
<div className={styles.minute_buttons}>
|
<div className={styles.minute_buttons}>
|
||||||
<Button label='-1 мин' onClick={handleSubstract}/>
|
<Button label='-1 мин' onClick={handleSubstraction}/>
|
||||||
<Button label='+1 мин' onClick={handleAdd}/>
|
<Button label='+1 мин' onClick={handleAdd}/>
|
||||||
</div>
|
</div>
|
||||||
<Button label='X' onClick={() => handleRecreation(-1)}/>
|
<Button label='X' onClick={() => handleRecreation(-1)}/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue