From 64753586e302f1ae8d6a2713297a19fa69ff9ac1 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 2 Jul 2020 09:12:51 +0300 Subject: [PATCH] Clear recurrence options when changing freq. Apparently iCal.js doesn't filter it itself so we have to do it, otherwise we can create malformed recurrence options. Fixes #134. --- src/widgets/RRule.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/widgets/RRule.tsx b/src/widgets/RRule.tsx index acdc41e..64cbe4f 100644 --- a/src/widgets/RRule.tsx +++ b/src/widgets/RRule.tsx @@ -119,9 +119,14 @@ interface PropsType { export default function RRule(props: PropsType) { const options = props.rrule; - function updateRule(newOptions: Partial): void { + function updateRule(newOptions: Partial, reset = false): void { const updatedOptions: RRuleOptions = { ...options, ...newOptions }; + if (reset) { + props.onChange(updatedOptions); + return; + } + for (const key of Object.keys(updatedOptions)) { const value = updatedOptions[key]; if ((value === undefined) || (value?.length === 0)) { @@ -149,7 +154,7 @@ export default function RRule(props: PropsType) { style={{ marginLeft: '0.5em' }} onChange={(event: React.FormEvent<{ value: unknown }>) => { const freq = (event.target as HTMLSelectElement).value as ICAL.FrequencyValues; - updateRule({ freq: freq }); + updateRule({ freq: freq }, true); }} > {menuItemsFrequency}