Skip to content

Commit 0841603

Browse files
committed
refactor(react/settings): use FormGroup for time selector
1 parent 59ba6a0 commit 0841603

File tree

3 files changed

+55
-52
lines changed

3 files changed

+55
-52
lines changed

apps/client/src/widgets/type_widgets/options/components/TimeSelector.tsx

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import toast from "../../../../services/toast";
1010
type TimeSelectorScale = "seconds" | "minutes" | "hours" | "days";
1111

1212
interface TimeSelectorProps {
13+
id?: string;
1314
name: string;
14-
label: string;
1515
optionValueId: keyof OptionDefinitions;
1616
optionTimeScaleId: keyof OptionDefinitions;
1717
includedTimeScales?: Set<TimeSelectorScale>;
@@ -23,7 +23,7 @@ interface TimeScaleInfo {
2323
unit: string;
2424
}
2525

26-
export default function TimeSelector({ name, label, includedTimeScales, optionValueId, optionTimeScaleId, minimumSeconds }: TimeSelectorProps) {
26+
export default function TimeSelector({ id, name, includedTimeScales, optionValueId, optionTimeScaleId, minimumSeconds }: TimeSelectorProps) {
2727
const values = useMemo(() => {
2828
const values: TimeScaleInfo[] = [];
2929
const timeScalesWithDefault = includedTimeScales ?? new Set(["seconds", "minutes", "hours", "days"]);
@@ -48,38 +48,37 @@ export default function TimeSelector({ name, label, includedTimeScales, optionVa
4848
}, [ value, scale ]);
4949

5050
return (
51-
<FormGroup label={label}>
52-
<div class="d-flex gap-2">
53-
<FormTextBox
54-
name={name}
55-
type="number" min={0} step={1} required
56-
currentValue={displayedTime} onChange={(value, validity) => {
57-
if (!validity.valid) {
58-
toast.showError(t("time_selector.invalid_input"));
59-
return false;
60-
}
51+
<div class="d-flex gap-2">
52+
<FormTextBox
53+
id={id}
54+
name={name}
55+
type="number" min={0} step={1} required
56+
currentValue={displayedTime} onChange={(value, validity) => {
57+
if (!validity.valid) {
58+
toast.showError(t("time_selector.invalid_input"));
59+
return false;
60+
}
6161

62-
let time = parseInt(value, 10);
63-
const minimumSecondsOrDefault = (minimumSeconds ?? 0);
64-
const newTime = convertTime(time, scale).toOption();
62+
let time = parseInt(value, 10);
63+
const minimumSecondsOrDefault = (minimumSeconds ?? 0);
64+
const newTime = convertTime(time, scale).toOption();
6565

66-
if (Number.isNaN(time) || newTime < (minimumSecondsOrDefault)) {
67-
toast.showError(t("time_selector.minimum_input", { minimumSeconds: minimumSecondsOrDefault }));
68-
time = minimumSecondsOrDefault;
69-
}
66+
if (Number.isNaN(time) || newTime < (minimumSecondsOrDefault)) {
67+
toast.showError(t("time_selector.minimum_input", { minimumSeconds: minimumSecondsOrDefault }));
68+
time = minimumSecondsOrDefault;
69+
}
7070

71-
setValue(newTime);
72-
}}
73-
/>
71+
setValue(newTime);
72+
}}
73+
/>
7474

75-
<FormSelect
76-
values={values}
77-
keyProperty="value" titleProperty="unit"
78-
style={{ width: "auto" }}
79-
currentValue={scale} onChange={setScale}
80-
/>
81-
</div>
82-
</FormGroup>
75+
<FormSelect
76+
values={values}
77+
keyProperty="value" titleProperty="unit"
78+
style={{ width: "auto" }}
79+
currentValue={scale} onChange={setScale}
80+
/>
81+
</div>
8382
)
8483
}
8584

apps/client/src/widgets/type_widgets/options/other.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ function NoteErasureTimeout() {
104104
return (
105105
<OptionsSection title={t("note_erasure_timeout.note_erasure_timeout_title")}>
106106
<FormText>{t("note_erasure_timeout.note_erasure_description")}</FormText>
107-
<TimeSelector
108-
name="erase-entities-after"
109-
label={t("note_erasure_timeout.erase_notes_after")}
110-
optionValueId="eraseEntitiesAfterTimeInSeconds" optionTimeScaleId="eraseEntitiesAfterTimeScale"
111-
/>
107+
<FormGroup label={t("note_erasure_timeout.erase_notes_after")}>
108+
<TimeSelector
109+
name="erase-entities-after"
110+
optionValueId="eraseEntitiesAfterTimeInSeconds" optionTimeScaleId="eraseEntitiesAfterTimeScale"
111+
/>
112+
</FormGroup>
112113
<FormText>{t("note_erasure_timeout.manual_erasing_description")}</FormText>
113114

114115
<Button
@@ -127,11 +128,12 @@ function AttachmentErasureTimeout() {
127128
return (
128129
<OptionsSection title={t("attachment_erasure_timeout.attachment_erasure_timeout")}>
129130
<FormText>{t("attachment_erasure_timeout.attachment_auto_deletion_description")}</FormText>
130-
<TimeSelector
131-
name="erase-unused-attachments-after"
132-
label={t("attachment_erasure_timeout.erase_attachments_after")}
133-
optionValueId="eraseUnusedAttachmentsAfterSeconds" optionTimeScaleId="eraseUnusedAttachmentsAfterTimeScale"
134-
/>
131+
<FormGroup label={t("attachment_erasure_timeout.erase_attachments_after")}>
132+
<TimeSelector
133+
name="erase-unused-attachments-after"
134+
optionValueId="eraseUnusedAttachmentsAfterSeconds" optionTimeScaleId="eraseUnusedAttachmentsAfterTimeScale"
135+
/>
136+
</FormGroup>
135137
<FormText>{t("attachment_erasure_timeout.manual_erasing_description")}</FormText>
136138

137139
<Button
@@ -155,12 +157,13 @@ function RevisionSnapshotInterval() {
155157
components={{ doc: <a href="https://triliumnext.github.io/Docs/Wiki/note-revisions.html" class="external" />}}
156158
/>
157159
</FormText>
158-
<TimeSelector
159-
name="revision-snapshot-time-interval"
160-
label={t("revisions_snapshot_interval.snapshot_time_interval_label")}
161-
optionValueId="revisionSnapshotTimeInterval" optionTimeScaleId="revisionSnapshotTimeIntervalTimeScale"
162-
minimumSeconds={10}
163-
/>
160+
<FormGroup label={t("revisions_snapshot_interval.snapshot_time_interval_label")}>
161+
<TimeSelector
162+
name="revision-snapshot-time-interval"
163+
optionValueId="revisionSnapshotTimeInterval" optionTimeScaleId="revisionSnapshotTimeIntervalTimeScale"
164+
minimumSeconds={10}
165+
/>
166+
</FormGroup>
164167
</OptionsSection>
165168
)
166169
}

apps/client/src/widgets/type_widgets/options/password.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ function ProtectedSessionTimeout() {
114114
<a class="tn-link" href="https://triliumnext.github.io/Docs/Wiki/protected-notes.html" className="external">{t("password.wiki")}</a> {t("password.for_more_info")}
115115
</FormText>
116116

117-
<TimeSelector
118-
name="protected-session-timeout"
119-
label={t("password.protected_session_timeout_label")}
120-
optionValueId="protectedSessionTimeout" optionTimeScaleId="protectedSessionTimeoutTimeScale"
121-
minimumSeconds={60}
122-
/>
117+
<FormGroup label={t("password.protected_session_timeout_label")}>
118+
<TimeSelector
119+
name="protected-session-timeout"
120+
optionValueId="protectedSessionTimeout" optionTimeScaleId="protectedSessionTimeoutTimeScale"
121+
minimumSeconds={60}
122+
/>
123+
</FormGroup>
123124
</OptionsSection>
124125
)
125126
}

0 commit comments

Comments
 (0)