Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/routes/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ const Home = () => {
});
};

/**
* Change a number value
* @param e The change event
* @param action The action to dispatch
*/
const changeNumberValue = (e, action) => {
if (e.target.value && e.target.value.length > 0) {
switch (action) {
case 'min':
d2(setPasswordLengthMin(parseInt(e.target.value, 10)));
break;
case 'max':
d2(setPasswordLengthMax(parseInt(e.target.value, 10)));
break;
case 'amount':
default:
d2(setPasswordAmount(parseInt(e.target.value, 10)));
break;
}
}
};

useEffect(() => {
d1(setPageIndex(0));
}, []);
Expand All @@ -122,7 +144,7 @@ const Home = () => {
value={min}
error={min > max}
fullWidth
onChange={(e) => d2(setPasswordLengthMin(parseInt(e.target.value, 10)))}
onChange={(e) => changeNumberValue(e, 'min')}
/>
</Grid>
<Grid item xs={12} md={12} lg={12}>
Expand All @@ -133,7 +155,7 @@ const Home = () => {
value={max}
error={max < min}
fullWidth
onChange={(e) => d2(setPasswordLengthMax(parseInt(e.target.value, 10)))}
onChange={(e) => changeNumberValue(e, 'max')}
/>
</Grid>
<Grid item xs={12} md={12} lg={12}>
Expand All @@ -143,11 +165,7 @@ const Home = () => {
label={language.amount}
value={amount}
error={amount.length === 0 || amount < 1}
onChange={(e) => {
if (e.target.value && e.target.value.length > 0) {
d2(setPasswordAmount(parseInt(e.target.value, 10)));
}
}}
onChange={(e) => changeNumberValue(e, 'amount')}
fullWidth
/>
</Grid>
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8792,11 +8792,11 @@ __metadata:
linkType: hard

"json5@npm:^2.1.2, json5@npm:^2.2.0, json5@npm:^2.2.1":
version: 2.2.1
resolution: "json5@npm:2.2.1"
version: 2.2.2
resolution: "json5@npm:2.2.2"
bin:
json5: lib/cli.js
checksum: 74b8a23b102a6f2bf2d224797ae553a75488b5adbaee9c9b6e5ab8b510a2fc6e38f876d4c77dea672d4014a44b2399e15f2051ac2b37b87f74c0c7602003543b
checksum: 9a878d66b72157b073cf0017f3e5d93ec209fa5943abcb38d37a54b208917c166bd473c26a24695e67a016ce65759aeb89946592991f8f9174fb96c8e2492683
languageName: node
linkType: hard

Expand Down