Skip to content

Commit

Permalink
Add vuex mutation and commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkup committed Mar 3, 2024
1 parent 7e76319 commit 2c6314e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/components/AppSidebar/RepeatItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/AppSidebar/RepeatItem/RepeatFreqInterval.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
type="number"
min="1"
max="366"
@input="$emit('update:interval', $event.target.value)">
@input="$emit('change-interval', $event.target.value)">
<RepeatFreqSelect :freq="frequency"
:count="interval"
@change="changeFrequency" />
Expand All @@ -53,7 +53,7 @@ export default {
required: true,
},
},
emits: ['update:frequency', 'update:interval'],
emits: ['change-frequency', 'change-interval'],
computed: {
repeatEveryLabel() {
if (this.frequency === 'NONE') {
Expand All @@ -67,7 +67,7 @@ export default {
},
methods: {
changeFrequency(value) {
this.$emit('update:frequency', value)
this.$emit('change-frequency', value)
},
},
}
Expand Down
26 changes: 23 additions & 3 deletions src/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/store/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
6 changes: 4 additions & 2 deletions src/views/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,13 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<template #icon>
<Repeat :size="20" />
</template>
<RepeatItem :value="task.recurrenceRule"
<RepeatItem :value="task.recurrenceRuleObject"
:disabled="readOnly"
:read-only="readOnly"
:placeholder="t('tasks', 'No recurrence')"
:task="task"
icon="IconRepeat" />
icon="IconRepeat"
@set-value="({task, value}) => setRecurrence({ task, rruleObject: value })" />
</NcAppSidebarTab>
</NcAppSidebar>
</template>
Expand Down Expand Up @@ -724,6 +725,7 @@ export default {
'setNote',
'setPriority',
'setLocation',
'setRecurrence',
'setUrl',
'setPercentComplete',
'setTags',
Expand Down

0 comments on commit 2c6314e

Please sign in to comment.