Skip to content

Commit a07c5f6

Browse files
committed
Smaller UI bugfixes
fixed: text fields get value "value" when beeing empty fixed: resolution of day before schedule fix: set* must result in an updated instance fix: MenuItem needs key
1 parent 64c9732 commit a07c5f6

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

src/settings/dialogs/CopyDayDialog.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,52 @@ const CopyDayDialog: React.FunctionComponent<Props> = (props: Props) => {
2525
setDays(null);
2626
}, [props.open]);
2727

28-
const toggleDay = (day) => setDays((oldDays) => {
29-
if (oldDays == null) { oldDays = []; }
28+
const toggleDay = (day) => () => {
29+
setDays((oldDays) => {
30+
if (oldDays == null) { oldDays = []; }
3031

31-
const found = find(oldDays, (d) => d === day);
32-
remove(oldDays, (d) => d === day);
32+
const found = find(oldDays, (d) => d === day);
33+
remove(oldDays, (d) => d === day);
3334

34-
if (found == null) {
35-
oldDays.push(day);
36-
}
35+
if (found == null) {
36+
oldDays.push(day);
37+
}
3738

38-
return oldDays;
39-
});
39+
// needs to be a new reference to update
40+
return [...oldDays];
41+
});
42+
};
43+
44+
const checkDay = (day) => {
45+
return find(days, (d) => d === day) != null;
46+
};
4047

4148
return (
4249
<Dialog open={props.open} onClose={() => { props.onCancel(); }} TransitionComponent={Transition}>
4350
<DialogTitle>{translate("copy.title")}</DialogTitle>
4451
<DialogContent>
4552
<DialogContentText>
46-
{translate("copy.text")}
53+
{translate("copy.text")}
4754
</DialogContentText>
4855

4956
<List dense={true}>
5057
{map([1, 2, 3, 4, 5, 6, 0], (day) => (
51-
<ListItem key={day} button={true} onClick={() => toggleDay(day)}>
58+
<ListItem key={day} button={true} onClick={toggleDay(day)}>
5259
<ListItemText primary={translate(`copy.${Day[day]}`)} />
5360
<ListItemSecondaryAction>
54-
<Checkbox checked={find(days, (d) => d === day) != null} onClick={() => toggleDay(day)} />
61+
<Checkbox checked={checkDay(day)} onClick={toggleDay(day)} />
5562
</ListItemSecondaryAction>
5663
</ListItem>
5764
))}
5865
</List>
5966
</DialogContent>
6067
<DialogActions>
6168
<Button onClick={() => { props.onCancel(); }} color="primary">
62-
{translate("copy.cancel")}
69+
{translate("copy.cancel")}
6370
</Button>
6471

6572
<Button onClick={() => { props.onConfirm(days); }} color="primary">
66-
{translate("copy.ok")}
73+
{translate("copy.ok")}
6774
</Button>
6875
</DialogActions>
6976
</Dialog>

src/settings/pages/overview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const OverviewPage: React.FunctionComponent<Props> = (props) => {
105105
>
106106
{
107107
[0, 1, 2, 3, 4, 5].map((m) =>
108-
(<MenuItem value={m}>{translate(`Modes.${m}`)}</MenuItem>),
108+
(<MenuItem key={m} value={m}>{translate(`Modes.${m}`)}</MenuItem>),
109109
)
110110
}
111111
</Select>
@@ -115,7 +115,7 @@ const OverviewPage: React.FunctionComponent<Props> = (props) => {
115115
{ plans.length === 0
116116
? <BodyText style={{paddingTop: 16}} text={translate("plans.plans.empty")} />
117117
: <List className={classes.list}>
118-
{plans.length > 0 && <Divider />}
118+
{plans.length > 0 && <Divider key="0" />}
119119
{plans.map((plan) => (
120120
<React.Fragment key={plan.id}>
121121
<ListItem {...{ to: `/plans/${plan.id}` }} component={Link} button={true}>

src/settings/pages/settings.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ const SettingsPage: React.FunctionComponent<Props> = (props) => {
3636
return val == null ? def : val;
3737
}
3838

39-
const updateField = (name: SettingsName) => (event) => {
40-
const val = event.target.value || (event.target.checked != null ? event.target.checked : null);
39+
const updateField = (name: SettingsName, field: "value" | "checked" = "value") => (event) => {
40+
const val = event.target[field];
4141

4242
setSettings((old) => {
4343
return { ...old, [name]: val };
@@ -96,7 +96,7 @@ const SettingsPage: React.FunctionComponent<Props> = (props) => {
9696
control={
9797
<Switch
9898
checked={getFieldValue("LogEnabled") === true}
99-
onChange={updateField("LogEnabled")}
99+
onChange={updateField("LogEnabled", "checked")}
100100
/>
101101
}
102102
label={translate("settings.enabled.label")}
@@ -107,6 +107,7 @@ const SettingsPage: React.FunctionComponent<Props> = (props) => {
107107
label={translate("settings.category.label")}
108108
placeholder={translate("settings.category.placeholder")}
109109

110+
required={getFieldValue("LogEnabled") === true}
110111
value={getFieldValue("LogCategory", "")}
111112
onChange={updateField("LogCategory")}
112113
/>

src/settings/pages/temperatures.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const TemperaturesPage: React.FunctionComponent<Props> = (props) => {
8484
>
8585
{
8686
[0, 1, 2, 3, 4, 5].map((m) =>
87-
(<MenuItem value={m}>{translate(`Modes.${m}`)}</MenuItem>),
87+
(<MenuItem key={m} value={m}>{translate(`Modes.${m}`)}</MenuItem>),
8888
)
8989
}
9090
</Select>

src/settings/state/PlanReducer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ const reducerImplementation = (state: State, action: Action) => {
395395

396396
// we search from right to left
397397
while (nd >= 0) {
398-
const last = state.plan.schedule.filter((sp) => sp.day === action.day);
398+
const last = state.plan.schedule.filter((sp) => sp.day === nd);
399+
399400
if (last.length > 0) {
400401
// already sorted
401402
return last[last.length - 1];

0 commit comments

Comments
 (0)