Skip to content

Commit 1a49324

Browse files
authored
Merge pull request #36 from CodeDead/feature/refactoring
feature/refactoring
2 parents 767b62f + a9ed5bd commit 1a49324

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/routes/Home/index.jsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,28 @@ const Home = () => {
9999
});
100100
};
101101

102+
/**
103+
* Change a number value
104+
* @param e The change event
105+
* @param action The action to dispatch
106+
*/
107+
const changeNumberValue = (e, action) => {
108+
if (e.target.value && e.target.value.length > 0) {
109+
switch (action) {
110+
case 'min':
111+
d2(setPasswordLengthMin(parseInt(e.target.value, 10)));
112+
break;
113+
case 'max':
114+
d2(setPasswordLengthMax(parseInt(e.target.value, 10)));
115+
break;
116+
case 'amount':
117+
default:
118+
d2(setPasswordAmount(parseInt(e.target.value, 10)));
119+
break;
120+
}
121+
}
122+
};
123+
102124
useEffect(() => {
103125
d1(setPageIndex(0));
104126
}, []);
@@ -122,7 +144,7 @@ const Home = () => {
122144
value={min}
123145
error={min > max}
124146
fullWidth
125-
onChange={(e) => d2(setPasswordLengthMin(parseInt(e.target.value, 10)))}
147+
onChange={(e) => changeNumberValue(e, 'min')}
126148
/>
127149
</Grid>
128150
<Grid item xs={12} md={12} lg={12}>
@@ -133,7 +155,7 @@ const Home = () => {
133155
value={max}
134156
error={max < min}
135157
fullWidth
136-
onChange={(e) => d2(setPasswordLengthMax(parseInt(e.target.value, 10)))}
158+
onChange={(e) => changeNumberValue(e, 'max')}
137159
/>
138160
</Grid>
139161
<Grid item xs={12} md={12} lg={12}>
@@ -143,11 +165,7 @@ const Home = () => {
143165
label={language.amount}
144166
value={amount}
145167
error={amount.length === 0 || amount < 1}
146-
onChange={(e) => {
147-
if (e.target.value && e.target.value.length > 0) {
148-
d2(setPasswordAmount(parseInt(e.target.value, 10)));
149-
}
150-
}}
168+
onChange={(e) => changeNumberValue(e, 'amount')}
151169
fullWidth
152170
/>
153171
</Grid>

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8792,11 +8792,11 @@ __metadata:
87928792
linkType: hard
87938793

87948794
"json5@npm:^2.1.2, json5@npm:^2.2.0, json5@npm:^2.2.1":
8795-
version: 2.2.1
8796-
resolution: "json5@npm:2.2.1"
8795+
version: 2.2.2
8796+
resolution: "json5@npm:2.2.2"
87978797
bin:
87988798
json5: lib/cli.js
8799-
checksum: 74b8a23b102a6f2bf2d224797ae553a75488b5adbaee9c9b6e5ab8b510a2fc6e38f876d4c77dea672d4014a44b2399e15f2051ac2b37b87f74c0c7602003543b
8799+
checksum: 9a878d66b72157b073cf0017f3e5d93ec209fa5943abcb38d37a54b208917c166bd473c26a24695e67a016ce65759aeb89946592991f8f9174fb96c8e2492683
88008800
languageName: node
88018801
linkType: hard
88028802

0 commit comments

Comments
 (0)