Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): choose the frequency by segments, not a menu within the menu

Elian Dorane36cd1f83b87
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 59093aec9e..3a4d8fc64c 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1019,6 +1019,7 @@
"recurrence": {
"repeats": "Repeats",
"frequency": "Frequency",
+ "none": "None",
"does_not_repeat": "Does not repeat",
"daily": "Daily",
"weekly": "Weekly",
diff --git a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.css b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.css
index 24e316b8e9..056a62d422 100644
--- a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.css
+++ b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.css
@@ -20,6 +20,12 @@
/* Room for the widest of its rows — the seven weekday pills — to breathe. */
min-width: 300px;
}
+
+ /* A locale that writes the frequencies long breaks the segments onto a second line rather
+ than stretching the menu across the calendar. */
+ .tn-segmented-choice {
+ flex-wrap: wrap;
+ }
}
.calendar-recurrence-weekdays {
diff --git a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx
index 5b915ba01e..e8ced332f6 100644
--- a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx
+++ b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx
@@ -10,6 +10,7 @@ import Dropdown from "../../react/Dropdown";
import FormSelect from "../../react/FormSelect";
import FormTextBox, { FormTextBoxWithUnit } from "../../react/FormTextBox";
import { useNoteLabel, useUniqueName } from "../../react/hooks";
+import SegmentedChoice from "../../react/SegmentedChoice";
import { EventField, EventFieldControls, EventFieldList } from "./EventField";
import {
FREQUENCIES,
@@ -89,38 +90,39 @@ function modelTitle(model: ParsedRecurrence): string {
}
}
-/** What the frequency dropdown offers beside the frequencies themselves. */
+/** What the frequency choice offers beside the frequencies themselves. */
const NO_REPEAT = "none";
const CUSTOM = "custom";
/**
- * The rule's headline: how often, or not at all. A rule beyond the structured fields shows as
- * "Custom" — an entry that exists only while it is the answer, since there is no such thing as
- * asking for a custom rule with nothing to say in it.
+ * The rule's headline: how often, or not at all. Segmented buttons rather than a select — a select
+ * inside the already-open menu is a menu within a menu — and every choice on show at once. A rule
+ * beyond the structured fields shows as "Custom", a segment that exists only while it is the
+ * answer, since there is no such thing as asking for a custom rule with nothing to say in it.
*/
function FrequencyField({ model, commit }: {
model: ParsedRecurrence;
commit(next: ParsedRecurrence): void;
}) {
- const selectId = useUniqueName("recurrence-frequency");
const current = model.kind === "simple" ? model.rule.frequency
: model.kind === "custom" ? CUSTOM : NO_REPEAT;
const choices = [
- { key: NO_REPEAT, title: t("calendar.recurrence.does_not_repeat") },
- ...FREQUENCIES.map((frequency) => ({ key: frequency, title: FREQUENCY_TITLES[frequency]() })),
- ...(model.kind === "custom" ? [ { key: CUSTOM, title: t("calendar.recurrence.custom") } ] : [])
+ // "None" rather than the closed row's "Does not repeat": a segment is a word, not a sentence.
+ { value: NO_REPEAT, label: t("calendar.recurrence.none") },
+ ...FREQUENCIES.map((frequency) => ({ value: frequency, label: FREQUENCY_TITLES[frequency]() })),
+ ...(model.kind === "custom" ? [ { value: CUSTOM, label: t("calendar.recurrence.custom") } ] : [])
];
- const onChange = (key: string) => {
- if (key === current) return;
+ const onChange = (value: string) => {
+ if (value === current) return;
- if (key === NO_REPEAT) {
+ if (value === NO_REPEAT) {
commit({ kind: "none" });
return;
}
- const frequency = FREQUENCIES.find((f) => f === key);
+ const frequency = FREQUENCIES.find((f) => f === value);
if (!frequency) return;
// What the old rule already said — how often within its period, and when it stops — is
@@ -138,15 +140,8 @@ function FrequencyField({ model, commit }: {
};
return (
- <EventField name={t("calendar.recurrence.frequency")} htmlFor={selectId}>
- <FormSelect
- id={selectId}
- values={choices}
- keyProperty="key"
- titleProperty="title"
- currentValue={current}
- onChange={onChange}
- />
+ <EventField name={t("calendar.recurrence.frequency")}>
+ <SegmentedChoice options={choices} currentValue={current} onChange={onChange} />
</EventField>
);
}