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.
master
Tom Hacohen 4 years ago
parent 9400abdbf4
commit 64753586e3

@ -119,9 +119,14 @@ interface PropsType {
export default function RRule(props: PropsType) { export default function RRule(props: PropsType) {
const options = props.rrule; const options = props.rrule;
function updateRule(newOptions: Partial<RRuleOptions>): void { function updateRule(newOptions: Partial<RRuleOptions>, reset = false): void {
const updatedOptions: RRuleOptions = { ...options, ...newOptions }; const updatedOptions: RRuleOptions = { ...options, ...newOptions };
if (reset) {
props.onChange(updatedOptions);
return;
}
for (const key of Object.keys(updatedOptions)) { for (const key of Object.keys(updatedOptions)) {
const value = updatedOptions[key]; const value = updatedOptions[key];
if ((value === undefined) || (value?.length === 0)) { if ((value === undefined) || (value?.length === 0)) {
@ -149,7 +154,7 @@ export default function RRule(props: PropsType) {
style={{ marginLeft: '0.5em' }} style={{ marginLeft: '0.5em' }}
onChange={(event: React.FormEvent<{ value: unknown }>) => { onChange={(event: React.FormEvent<{ value: unknown }>) => {
const freq = (event.target as HTMLSelectElement).value as ICAL.FrequencyValues; const freq = (event.target as HTMLSelectElement).value as ICAL.FrequencyValues;
updateRule({ freq: freq }); updateRule({ freq: freq }, true);
}} }}
> >
{menuItemsFrequency} {menuItemsFrequency}

Loading…
Cancel
Save