Skip to content

Commit

Permalink
fixup! feat: add a setting for the default calendar url
Browse files Browse the repository at this point in the history
  • Loading branch information
st3iny committed Feb 27, 2024
1 parent 87bdacc commit 8b83768
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/mixins/EditorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,10 @@ export default {
const start = parseInt(to.params.dtstart, 10)
const end = parseInt(to.params.dtend, 10)
const timezoneId = vm.$store.getters.getResolvedTimezone
const calendarId = vm.$store.state.settings.defaultCalendarId

try {
await vm.loadingCalendars()
await vm.$store.dispatch('getCalendarObjectInstanceForNewEvent', { isAllDay, start, end, timezoneId, calendarId })
await vm.$store.dispatch('getCalendarObjectInstanceForNewEvent', { isAllDay, start, end, timezoneId })
vm.calendarId = vm.calendarObject.calendarId
} catch (error) {
console.debug(error)
Expand Down
5 changes: 2 additions & 3 deletions src/store/calendarObjectInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1563,15 +1563,15 @@ const actions = {
* @param {string} data.timezoneId The timezoneId of the new event
* @return {Promise<{calendarObject: object, calendarObjectInstance: object}>}
*/
async getCalendarObjectInstanceForNewEvent({ state, dispatch, commit }, { isAllDay, start, end, timezoneId, calendarId }) {
async getCalendarObjectInstanceForNewEvent({ state, dispatch, commit }, { isAllDay, start, end, timezoneId }) {
if (state.isNew === true) {
return Promise.resolve({
calendarObject: state.calendarObject,
calendarObjectInstance: state.calendarObjectInstance,
})
}

const calendarObject = await dispatch('createNewEvent', { start, end, isAllDay, timezoneId, calendarId })
const calendarObject = await dispatch('createNewEvent', { start, end, isAllDay, timezoneId })
const startDate = new Date(start * 1000)
const eventComponent = getObjectAtRecurrenceId(calendarObject, startDate)
const calendarObjectInstance = mapEventComponentToEventObject(eventComponent)
Expand Down Expand Up @@ -1708,7 +1708,6 @@ const actions = {
end: endDate.unixTime,
timezoneId: oldEventComponent.startDate.timezoneId,
isAllDay: oldEventComponent.isAllDay(),
calendarId: oldEventComponent.calendarId,
})
const eventComponent = getObjectAtRecurrenceId(calendarObject, startDate.jsDate)
copyCalendarObjectInstanceIntoEventComponent(oldCalendarObjectInstance, eventComponent)
Expand Down
35 changes: 1 addition & 34 deletions src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { enableBirthdayCalendar, getCurrentUserPrincipal } from '../services/caldavService.js'
import { enableBirthdayCalendar } from '../services/caldavService.js'
import { mapDavCollectionToCalendar } from '../models/calendar.js'
import { detectTimezone } from '../services/timezoneDetectionService.js'
import { setConfig as setCalendarJsConfig } from '@nextcloud/calendar-js'
Expand Down Expand Up @@ -56,7 +55,6 @@ const state = {
momentLocale: 'en',
attachmentsFolder: '/Calendar',
attachmentsFolderCreated: false,
defaultCalendarUrl: null,
}

const mutations = {
Expand Down Expand Up @@ -162,17 +160,6 @@ const mutations = {
state.attachmentsFolderCreated = attachmentsFolderCreated
},

/**
* Updates the user's default calendar
*
* @param {Object} state The Vuex state
* @param {Object} data The destructuring object
* @param {String} data.calendarId The new calendar id
*/
setDefaultCalendarUrl(state, { calendarUrl }) {
state.defaultCalendarUrl = calendarUrl
},

/**
* Initialize settings
*
Expand Down Expand Up @@ -444,26 +431,6 @@ const actions = {
commit('setDefaultReminder', { defaultReminder })
},

/**
* Updates the user's default calendar for new events and invitations
*
* @param {object} vuex The Vuex destructuring object
* @param {object} vuex.state The Vuex state
* @param {Function} vuex.commit The Vuex commit Function
* @param {object} data The destructuring object
* @param {string} data.calendarUrl The url of the new default calendar
*/
async setDefaultCalendarUrl({ commit, state }, { calendarUrl }) {
if (state.defaultCalendarUrl === calendarUrl) {
return
}

const principal = getCurrentUserPrincipal()
principal.scheduleDefaultCalendarUrl = calendarUrl
await principal.update()
commit('setDefaultCalendarUrl', { calendarUrl })
},

/**
* Updates the user's timezone
*
Expand Down
1 change: 0 additions & 1 deletion src/views/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export default {
showWeekNumbers: state => state.settings.showWeekNumbers,
slotDuration: state => state.settings.slotDuration,
defaultReminder: state => state.settings.defaultReminder,
defaultCalendarId: state => state.settings.defaultCalendarId,
showTasks: state => state.settings.showTasks,
timezone: state => state.settings.timezone,
modificationCount: state => state.calendarObjects.modificationCount,
Expand Down
2 changes: 2 additions & 0 deletions tests/javascript/unit/models/principal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('Test suite: Principal model (models/principal.js)', () => {
isCalendarResource: false,
isCalendarRoom: false,
principalId: null,
scheduleDefaultCalendarUrl: null,
})
})

Expand All @@ -63,6 +64,7 @@ describe('Test suite: Principal model (models/principal.js)', () => {
isCalendarRoom: false,
principalId: 'bar',
otherProp: 'foo',
scheduleDefaultCalendarUrl: null,
})
})

Expand Down
7 changes: 0 additions & 7 deletions tests/javascript/unit/store/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('store/settings test suite', () => {
it('should provide a default state', () => {
expect(settingsStore.state).toEqual({
appVersion: null,
defaultCalendarId: null,
firstRun: null,
forceEventAlarmType: false,
hideEventExport: false,
Expand Down Expand Up @@ -163,7 +162,6 @@ describe('store/settings test suite', () => {
it('should provide a mutation to set the settings initially', () => {
const state = {
appVersion: null,
defaultCalendarId: null,
firstRun: null,
talkEnabled: false,
eventLimit: null,
Expand All @@ -188,7 +186,6 @@ describe('store/settings test suite', () => {

const settings = {
appVersion: '2.1.0',
defaultCalendarId: 'Personal',
eventLimit: false,
firstRun: true,
showWeekNumbers: true,
Expand Down Expand Up @@ -216,7 +213,6 @@ describe('store/settings test suite', () => {
expect(logInfo).toHaveBeenNthCalledWith(1, `
Initial settings:
- AppVersion: 2.1.0
- DefaultCalendarId: Personal
- EventLimit: false
- FirstRun: true
- ShowWeekNumbers: true
Expand All @@ -238,7 +234,6 @@ Initial settings:
`)
expect(state).toEqual({
appVersion: '2.1.0',
defaultCalendarId: 'Personal',
eventLimit: false,
firstRun: true,
showWeekNumbers: true,
Expand All @@ -265,7 +260,6 @@ Initial settings:
it('should provide a mutation to set the resolved moment locale', () => {
const state = {
appVersion: null,
defaultCalendarId: null,
firstRun: null,
talkEnabled: false,
eventLimit: null,
Expand All @@ -286,7 +280,6 @@ Initial settings:

expect(state).toEqual({
appVersion: null,
defaultCalendarId: null,
firstRun: null,
talkEnabled: false,
eventLimit: null,
Expand Down

0 comments on commit 8b83768

Please sign in to comment.