Skip to content

Commit ecd9278

Browse files
committed
Update to v1.4.0: Hint toggle and custom signal duration
1 parent 05d98ca commit ecd9278

File tree

11 files changed

+121
-126
lines changed

11 files changed

+121
-126
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lptimer",
3-
"version": "1.3.2",
3+
"version": "1.4.0",
44
"private": true,
55
"homepage": "https://kroljs.com/LP-Timer",
66
"dependencies": {

src/components/App.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ function App() {
2323
const initSettings = {
2424
"delay": 0,
2525
"durationMin": 7,
26-
"durationSec": "00",
27-
"showMS": false
26+
"signalDuration": 5,
27+
"showMS": false,
28+
"showTips": true
2829
};
2930
const [settingsOpen, setSettingsOpen] = useState(false);
3031
const [settings, setSettings] = useState(initSettings);
@@ -49,13 +50,25 @@ function App() {
4950
<Switch>
5051
<Route exact path="/" component={HomePage} />
5152
<Route path="/ext">
52-
<ExtPage min={settings.durationMin} delay={settings.delay} />
53+
<ExtPage
54+
min={settings.durationMin}
55+
delay={settings.delay}
56+
showTips={settings.showTips}
57+
signalDuration={settings.signalDuration} />
5358
</Route>
5459
<Route path="/imp">
55-
<ImpPage min={settings.durationMin} delay={settings.delay} />
60+
<ImpPage
61+
min={settings.durationMin}
62+
delay={settings.delay}
63+
showTips={settings.showTips}
64+
signalDuration={settings.signalDuration} />
5665
</Route>
5766
<Route path="/timer">
58-
<TimerPage min={settings.durationMin} delay={settings.delay} showMS={settings.showMS} />
67+
<TimerPage
68+
min={settings.durationMin}
69+
delay={settings.delay}
70+
showMS={settings.showMS}
71+
showTips={settings.showTips} />
5972
</Route>
6073
<Route path="/guide" component={GuidePage} />
6174
<Route path="/about" component={AboutPage} />

src/components/pages/AboutPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import Form from '../utilities/Form';
33
import '../../styles/AboutPage.css';
44
import { FiAlertTriangle } from 'react-icons/fi';
5+
import { version } from '../../../package.json';
56

67
function AboutPage() {
78
return (
@@ -14,7 +15,7 @@ function AboutPage() {
1415
<h3>Licensing</h3>
1516
<p>The limited preparation timer progressive web application is open-sourced under a MIT license. To read the conditions of this license, visit the <a href="https://github.com/jacobkrol/LP-Timer/blob/master/LICENSE" target="_blank" rel="noopener noreferrer">LICENSE file in the host repository</a>.</p>
1617
<h3>Updates</h3>
17-
<p>This is LP Timer PWA v1.3.2. You can check for the latest version <a href="https://github.com/jacobkrol/LP-Timer/releases" target="_blank" rel="noopener noreferrer">on the project releases page</a>.</p>
18+
<p>This is LP Timer PWA v{version}. You can check for the latest version <a href="https://github.com/jacobkrol/LP-Timer/releases" target="_blank" rel="noopener noreferrer">on the project releases page</a>.</p>
1819
</div>
1920
)
2021
}

src/components/pages/ExtPage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import Timer from '../utilities/Timer';
33

4-
function ExtPage({ min=7, delay=0 }) {
4+
function ExtPage({ min=7, delay=0, showTips=true, signalDuration=5 }) {
55
return (
66
<>
7-
<Timer mode="ext" min={min} delay={delay} />
7+
<Timer mode="ext" min={min} delay={delay} showTips={showTips} signalDuration={signalDuration} />
88
</>
99
)
1010
}

src/components/pages/ImpPage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import Timer from '../utilities/Timer';
33

4-
function ImpPage({ min=7, delay=0 }) {
4+
function ImpPage({ min=7, delay=0, showTips=true, signalDuration=5 }) {
55
return (
66
<>
7-
<Timer mode="imp" min={min} delay={delay} />
7+
<Timer mode="imp" min={min} delay={delay} showTips={showTips} signalDuration={signalDuration} />
88
</>
99
)
1010
}

src/components/pages/TimerPage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import Timer from '../utilities/Timer';
33

4-
function TimerPage({ min=7, delay=0, showMS=false }) {
4+
function TimerPage({ min=7, delay=0, showMS=false, showTips=true }) {
55
return (
66
<>
7-
<Timer mode="none" min={min} delay={delay} showMS={showMS} />
7+
<Timer mode="none" min={min} delay={delay} showMS={showMS} showTips={showTips} />
88
</>
99
)
1010
}

src/components/utilities/Form.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { Link } from 'react-router-dom';
33
import 'whatwg-fetch';
44
import '../../styles/Form.css';
5+
import { version } from '../../../package.json';
56

67
class Form extends React.Component {
78
state = {
@@ -92,7 +93,7 @@ class Form extends React.Component {
9293
getFormData = () => {
9394
let data = {...this.state};
9495
delete data.disabled;
95-
data['version'] = "1.3.2";
96+
data['version'] = version;
9697
return JSON.stringify(data);
9798
}
9899

src/components/utilities/Settings.js

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ const reducer = (state, action) => {
77
return {...state, delay: action.value};
88
case 'durationMin':
99
return {...state, durationMin: action.value};
10-
case 'durationSec':
11-
let value = String(action.value);
12-
if(Number(value) < 0) value = "0";
13-
if(Number(value) > 59) value = "59";
14-
if(Number(value) < 10) value = "0"+String(value);
15-
return {...state, durationSec: value};
10+
case 'signalDuration':
11+
return {...state, signalDuration: action.value};
1612
case 'showMS':
1713
return {...state, showMS: Boolean(action.value)};
14+
case 'showTips':
15+
return {...state, showTips: Boolean(action.value)};
1816
case 'all':
1917
return {...action.value};
2018
default:
@@ -23,7 +21,13 @@ const reducer = (state, action) => {
2321
}
2422
}
2523

26-
const SanitizeInt = (val) => val.replace(/\D/g, '');
24+
const SanitizeInt = (element, value) => {
25+
value = value.replace(/(?=\.).+/,'');
26+
value = value.replace(/[^0-9]/g,'');
27+
if(Number(value) < element.min) value = element.min;
28+
if(Number(value) > element.max) value = element.max;
29+
return Number(value);
30+
}
2731

2832
function Settings({ open, setOpen, settings, setSettings }) {
2933
const [state, dispatch] = useReducer(reducer, settings);
@@ -44,26 +48,38 @@ function Settings({ open, setOpen, settings, setSettings }) {
4448
id="settings-delay"
4549
name="delay"
4650
type="number"
51+
min="0"
52+
max="99"
4753
value={state.delay}
48-
onChange={(event) => dispatch({modify: "delay", value: SanitizeInt(event.target.value)})} />
54+
onChange={(event) => dispatch({modify: "delay", value: event.target.value})}
55+
onBlur={(event) => dispatch({modify: "delay", value: SanitizeInt(event.target, event.target.value)})} />
4956
<span>&nbsp;seconds</span>
5057
</div>
5158
<div className="setting-row">
52-
<label htmlFor="settings-duration-min">Duration</label>
59+
<label htmlFor="settings-duration-min">Timer Duration</label>
5360
<input
5461
id="settings-duration-min"
5562
name="durationMin"
5663
type="number"
64+
min="1"
65+
max="60"
5766
value={state.durationMin}
58-
onChange={(event) => dispatch({modify: "durationMin", value: SanitizeInt(event.target.value)})} />
67+
onChange={(event) => dispatch({modify: "durationMin", value: event.target.value})}
68+
onBlur={(event) => dispatch({modify: "durationMin", value: SanitizeInt(event.target, event.target.value)})} />
5969
<span>&nbsp;minutes</span>
60-
{/* <span>&nbsp;:&nbsp;</span>
70+
</div>
71+
<div className="setting-row">
72+
<label htmlFor="settings-signal-duration">Display Signals</label>
6173
<input
62-
id="settings-duration-sec"
63-
name="durationSec"
74+
id="settings-signal-duration"
75+
name="signalDuration"
6476
type="number"
65-
value={state.durationSec}
66-
onChange={(event) => dispatch({modify: "durationSec", value: SanitizeInt(event.target.value)})} /> */}
77+
min="1"
78+
max="59"
79+
value={state.signalDuration}
80+
onChange={(event) => dispatch({modify: "signalDuration", value: event.target.value})}
81+
onBlur={(event) => dispatch({modify: "signalDuration", value: SanitizeInt(event.target, event.target.value)})} />
82+
<span>&nbsp;seconds</span>
6783
</div>
6884
<div className="setting-row">
6985
<input
@@ -74,6 +90,15 @@ function Settings({ open, setOpen, settings, setSettings }) {
7490
onChange={(event) => dispatch({modify: "showMS", value: event.target.checked})} />
7591
<label htmlFor="settings-show-ms" className="after">Show milliseconds</label>
7692
</div>
93+
<div className="setting-row">
94+
<input
95+
id="settings-show-tips"
96+
name="showTips"
97+
type="checkbox"
98+
checked={state.showTips}
99+
onChange={(event) => dispatch({modify: "showTips", value: event.target.checked})} />
100+
<label htmlFor="settings-show-tips" className="after">Show hint details</label>
101+
</div>
77102
<div id="settings-button-row">
78103
<div
79104
className="setting-button"

0 commit comments

Comments
 (0)