-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from asherhe/dev
add timer settings
- Loading branch information
Showing
9 changed files
with
441 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useCallback } from "react"; | ||
|
||
/** | ||
* | ||
* @param {{val: boolean, setVal: (val: boolean) => void}} props | ||
*/ | ||
function CheckBox({ val, setVal }) { | ||
const onClick = useCallback(() => setVal(!val), [val, setVal]); | ||
|
||
return ( | ||
<input | ||
className="input-toggle" | ||
type="checkbox" | ||
defaultChecked={val} | ||
onClick={onClick} | ||
/> | ||
); | ||
} | ||
|
||
export default CheckBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useCallback } from "react"; | ||
|
||
/** | ||
* | ||
* @param {{val: number, setVal: (val: number) => void, min: number, max: number, step: number}} props | ||
*/ | ||
function NumberInput({ | ||
val, | ||
setVal, | ||
min = undefined, | ||
max = undefined, | ||
step = 1, | ||
}) { | ||
const onChange = useCallback( | ||
(e) => { | ||
let v = parseFloat(e.target.value); | ||
setVal(v); | ||
}, | ||
[setVal] | ||
); | ||
|
||
return ( | ||
<input | ||
className="input-number" | ||
type="number" | ||
value={val} | ||
min={min} | ||
max={max} | ||
step={step} | ||
onChange={onChange} | ||
/> | ||
); | ||
} | ||
|
||
export default NumberInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { useCallback, useState } from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faGear } from "@fortawesome/free-solid-svg-icons"; | ||
import NumberInput from "./number-input"; | ||
import CheckBox from "./checkbox"; | ||
|
||
/** | ||
* @typedef {{work: number, break: number, longbreak: number, longfreq: number, autoStart: boolean }} config | ||
* @type {config} | ||
*/ | ||
export const defaultConfig = { | ||
work: 1500, | ||
break: 300, | ||
longbreak: 900, | ||
longfreq: 4, | ||
autoStart: false, | ||
}; | ||
|
||
/** | ||
* @param {{config: config, setConfig: (v: config) => void}} props | ||
*/ | ||
export function TimerConfig({ config, setConfig }) { | ||
const [show, setShow] = useState(false); | ||
|
||
/** | ||
* sets some config property `prop` to `val` | ||
* @param {string} prop | ||
* @param {*} val | ||
*/ | ||
const setProp = useCallback( | ||
(prop, val) => { | ||
let c = structuredClone(config); | ||
c[prop] = val; | ||
setConfig(c); | ||
}, | ||
[config, setConfig] | ||
); | ||
|
||
return ( | ||
<div className={"timer-config" + (show ? " show" : "")}> | ||
<div className="timer-config-button" onClick={() => setShow(!show)}> | ||
<FontAwesomeIcon icon={faGear} /> | ||
</div> | ||
<div className="timer-config-menu"> | ||
<div className="timer-config-title">Settings</div> | ||
<div className="timer-config-list"> | ||
<div> | ||
<span className="timer-config-list-title">Work duration:</span> | ||
<span> | ||
<NumberInput | ||
val={config.work / 60} | ||
setVal={(v) => setProp("work", v * 60)} | ||
min="1" | ||
/> | ||
minutes | ||
</span> | ||
</div> | ||
<div> | ||
<span className="timer-config-list-title">Break duration:</span> | ||
<span> | ||
<NumberInput | ||
val={config.break / 60} | ||
setVal={(v) => setProp("break", v * 60)} | ||
min="1" | ||
/> | ||
minutes | ||
</span> | ||
</div> | ||
<div> | ||
<span className="timer-config-list-title"> | ||
Long break duration: | ||
</span> | ||
<span> | ||
<NumberInput | ||
val={config.longbreak / 60} | ||
setVal={(v) => setProp("longbreak", v * 60)} | ||
min="1" | ||
/> | ||
minutes | ||
</span> | ||
</div> | ||
<div> | ||
<span className="timer-config-list-title"> | ||
Long break frequency: | ||
</span> | ||
<span> | ||
<NumberInput | ||
val={config.longfreq} | ||
setVal={(v) => setProp("longfreq", v)} | ||
min="0" | ||
/> | ||
breaks | ||
</span> | ||
</div> | ||
<div> | ||
<span className="timer-config-list-title"> | ||
Auto start next timer? | ||
</span> | ||
<CheckBox | ||
val={config.autoStart} | ||
setVal={(v) => setProp("autoStart", v)} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.