From 4f25191b77b4db705bd4eac316c6ff89468f95fe Mon Sep 17 00:00:00 2001 From: Sunik Kupfer Date: Sun, 3 Mar 2024 20:22:25 +0100 Subject: [PATCH] Add vuex mutation and commit --- src/components/AppSidebar/RepeatItem.vue | 7 +++-- .../RepeatItem/RepeatFreqInterval.vue | 6 ++--- src/models/task.js | 26 ++++++++++++++++--- src/store/tasks.js | 26 +++++++++++++++++++ src/views/AppSidebar.vue | 6 +++-- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/components/AppSidebar/RepeatItem.vue b/src/components/AppSidebar/RepeatItem.vue index 631afa772..e082d4fb2 100644 --- a/src/components/AppSidebar/RepeatItem.vue +++ b/src/components/AppSidebar/RepeatItem.vue @@ -125,12 +125,15 @@ export default { }, changeFrequency(value) { this.frequency = value - // this.newValue = this.value.copy(interval = value) + // TODO: There should be a better way than using structuredClone + this.newValue = structuredClone(this.value) + this.newValue.frequency = value }, changeInterval(value) { logger.info('change Interval to ' + value) this.interval = value - // this.newValue = this.value.copy(interval = value) + this.newValue = structuredClone(this.value) + this.newValue.interval = value }, }, } diff --git a/src/components/AppSidebar/RepeatItem/RepeatFreqInterval.vue b/src/components/AppSidebar/RepeatItem/RepeatFreqInterval.vue index ce527fe8b..df74697ed 100644 --- a/src/components/AppSidebar/RepeatItem/RepeatFreqInterval.vue +++ b/src/components/AppSidebar/RepeatItem/RepeatFreqInterval.vue @@ -30,7 +30,7 @@ type="number" min="1" max="366" - @input="$emit('update:interval', $event.target.value)"> + @input="$emit('change-interval', $event.target.value)"> @@ -53,7 +53,7 @@ export default { required: true, }, }, - emits: ['update:frequency', 'update:interval'], + emits: ['change-frequency', 'change-interval'], computed: { repeatEveryLabel() { if (this.frequency === 'NONE') { @@ -67,7 +67,7 @@ export default { }, methods: { changeFrequency(value) { - this.$emit('update:frequency', value) + this.$emit('change-frequency', value) }, }, } diff --git a/src/models/task.js b/src/models/task.js index 44b869fe9..0b7c2d80a 100644 --- a/src/models/task.js +++ b/src/models/task.js @@ -82,6 +82,8 @@ export default class Task { this.vtodo = new ICAL.Component('vtodo') this.vCalendar.addSubcomponent(this.vtodo) } + + // From NC calendar-js this.todoComponent = ToDoComponent.fromICALJs(this.vtodo) if (!this.vtodo.hasProperty('uid')) { @@ -333,18 +335,36 @@ export default class Task { } /** - * Return the recurrence + * Get the recurrence * * @readonly * @memberof Task */ - get recurrenceRule() { + get recurrenceRuleObject() { if (this._recurrence === undefined || this._recurrence === null) { return getDefaultRecurrenceRuleObject() } return mapRecurrenceRuleValueToRecurrenceRuleObject(this._recurrence.getFirstValue(), this._start) } + /** + * Set the recurrence + * + * @readonly + * @memberof Task + */ + set recurrenceRuleObject(rruleObject) { + if (rruleObject === null) { + this.vtodo.removeProperty('rrule') + } else { + // FIXME: rruleObject.recurrenceRuleValue should not be null + this.vtodo.updatePropertyWithValue('rrule', rruleObject.recurrenceRuleValue) + } + this.todoComponent = ToDoComponent.fromICALJs(this.vtodo) + this._recurrence = this.todoComponent.getPropertyIterator('RRULE').next().value + this.updateLastModified() + } + /** * Whether this task repeats * @@ -754,7 +774,7 @@ export default class Task { */ completeRecurring() { // Get recurrence iterator, starting at start date - const iter = this.recurrenceRule.iterator(this.start) + const iter = this.recurrenceRuleObject.iterator(this.start) // Skip the start date itself iter.next() // If there is a next recurrence, update the start date to next recurrence date diff --git a/src/store/tasks.js b/src/store/tasks.js index a2c64a5c3..18019afd3 100644 --- a/src/store/tasks.js +++ b/src/store/tasks.js @@ -495,6 +495,18 @@ const mutations = { task.location = location }, + /** + * Sets the recurrence rule of a task + * + * @param {object} state The store data + * @param {object} data Destructuring object + * @param {Task} data.task The task + * @param {string} data.rruleObject The recurrence rule object from NC calendar-js + */ + setRecurrence(state, { task, rruleObject }) { + task.recurrenceRuleObject = rruleObject + }, + /** * Sets the url of a task * @@ -1232,6 +1244,20 @@ const actions = { context.dispatch('updateTask', task) }, + /** + * Sets the location of a task + * + * @param {object} context The store context + * @param {Task} task The task to update + */ + async setRecurrence(context, { task, rruleObject }) { + if (rruleObject === task.recurrenceRuleObject) { + return + } + context.commit('setRecurrence', { task, rruleObject }) + context.dispatch('updateTask', task) + }, + /** * Sets the URL of a task * diff --git a/src/views/AppSidebar.vue b/src/views/AppSidebar.vue index 219a05214..2b8c2a705 100644 --- a/src/views/AppSidebar.vue +++ b/src/views/AppSidebar.vue @@ -261,12 +261,13 @@ License along with this library. If not, see . - + icon="IconRepeat" + @set-value="({task, value}) => setRecurrence({ task, rruleObject: value })" /> @@ -724,6 +725,7 @@ export default { 'setNote', 'setPriority', 'setLocation', + 'setRecurrence', 'setUrl', 'setPercentComplete', 'setTags',