Skip to content

Commit

Permalink
Merge pull request #5705 from nextcloud/Migrate/vuex-to-pinia
Browse files Browse the repository at this point in the history
Migrate/vuex to pinia
  • Loading branch information
st3iny authored Jun 25, 2024
2 parents 3dd35fb + 88f6dd2 commit 8b5c9f4
Show file tree
Hide file tree
Showing 81 changed files with 5,112 additions and 5,619 deletions.
19 changes: 0 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
"vue-router": "^3.6.5",
"vue-shortkey": "^3.1.7",
"vuedraggable": "^2.24.3",
"vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0",
"webdav": "^5.6.0"
},
"browserslist": [
Expand Down Expand Up @@ -140,7 +138,7 @@
"clover"
],
"transformIgnorePatterns": [
"/node_modules/(?!(@fullcalendar|uuid|webdav)).+\\.js$"
"/node_modules/(?!(@fullcalendar|uuid|webdav|p-limit|yocto-queue)).+\\.js$"
],
"setupFilesAfterEnv": [
"./tests/javascript/jest.setup.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ import {
getDateFromFirstdayParam,
modifyDate,
} from '../../../utils/date.js'
import { mapState } from 'vuex'
import { mapState, mapStores } from 'pinia'
import formatDateRange from '../../../filters/dateRangeFormat.js'
import DatePicker from '../../Shared/DatePicker.vue'
import ChevronLeftIcon from 'vue-material-design-icons/ChevronLeft.vue'
import ChevronRightIcon from 'vue-material-design-icons/ChevronRight.vue'
import { NcButton } from '@nextcloud/vue'
import useSettingsStore from '../../../store/settings.js'
import useWidgetStore from '../../../store/widget.js'

export default {
name: 'AppNavigationHeaderDatePicker',
Expand All @@ -81,12 +83,13 @@ export default {
}
},
computed: {
...mapState({
locale: (state) => state.settings.momentLocale,
...mapStores(useWidgetStore),
...mapState(useSettingsStore, {
locale: 'momentLocale',
}),
selectedDate() {
if (this.isWidget) {
return getDateFromFirstdayParam(this.$store.getters.widgetDate)
return getDateFromFirstdayParam(this.widgetStore.widgetDate)
}
return getDateFromFirstdayParam(this.$route.params?.firstDay ?? 'now')
},
Expand Down Expand Up @@ -136,7 +139,7 @@ export default {
},
view() {
if (this.isWidget) {
return this.$store.getters.widgetView
return this.widgetStore.widgetView
}
return this.$route.params.view
},
Expand Down Expand Up @@ -190,7 +193,7 @@ export default {
},
navigateToDate(date) {
if (this.isWidget) {
this.$store.commit('setWidgetDate', { widgetDate: getYYYYMMDDFromDate(date) })
this.widgetStore.setWidgetDate({ widgetDate: getYYYYMMDDFromDate(date) })
} else {
const name = this.$route.name
const params = Object.assign({}, this.$route.params, {
Expand Down
27 changes: 15 additions & 12 deletions src/components/AppNavigation/AppointmentConfigList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ import AppointmentConfigModal from '../AppointmentConfigModal.vue'
import AppointmentConfig from '../../models/appointmentConfig.js'
import logger from '../../utils/logger.js'
import NoEmailAddressWarning from '../AppointmentConfigModal/NoEmailAddressWarning.vue'
import useAppointmentConfigStore from '../../store/appointmentConfigs.js'
import { mapStores } from 'pinia'
import useAppointmentConfigsStore from '../../store/appointmentConfigs.js'
import usePrincipalsStore from '../../store/principals.js'
import useCalendarsStore from '../../store/calendars.js'
import useSettingsStore from '../../store/settings.js'
import { mapStores, mapState } from 'pinia'

export default {
name: 'AppointmentConfigList',
Expand All @@ -71,22 +74,22 @@ export default {
}
},
computed: {
...mapStores(useAppointmentConfigStore),
configs() {
return this.appointmentConfigStore.allConfigs
},
...mapStores(useAppointmentConfigsStore, usePrincipalsStore, useCalendarsStore, useSettingsStore),
...mapState(useAppointmentConfigsStore, {
configs: (state) => state.allConfigs,
}),
defaultConfig() {
return AppointmentConfig.createDefault(
this.calendarUrlToUri(this.$store.getters.ownSortedCalendars[0].url),
this.$store.getters.scheduleInbox,
this.$store.getters.getResolvedTimezone,
this.calendarUrlToUri(this.calendarsStore.ownSortedCalendars[0].url),
this.calendarsStore.scheduleInbox,
this.settingsStore.getResolvedTimezone,
)
},
hasAtLeastOneCalendar() {
return !!this.$store.getters.ownSortedCalendars[0]
return !!this.calendarsStore.ownSortedCalendars[0]
},
hasUserEmailAddress() {
const principal = this.$store.getters.getCurrentUserPrincipal
const principal = this.principalsStore.getCurrentUserPrincipal
if (!principal) {
return false
}
Expand All @@ -111,7 +114,7 @@ export default {
logger.info('Deleting config', { config })

try {
await this.appointmentConfigStore.deleteConfig({ id: config.id })
await this.appointmentConfigsStore.deleteConfig({ id: config.id })

logger.info('Config deleted', { config })
} catch (error) {
Expand Down
10 changes: 6 additions & 4 deletions src/components/AppNavigation/CalendarList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import PublicCalendarListItem from './CalendarList/PublicCalendarListItem.vue'
import CalendarListItemLoadingPlaceholder from './CalendarList/CalendarListItemLoadingPlaceholder.vue'
import draggable from 'vuedraggable'
import debounce from 'debounce'
import { mapGetters } from 'vuex'
import { showError } from '@nextcloud/dialogs'
import pLimit from 'p-limit'
import { mapStores, mapState } from 'pinia'
import useCalendarsStore from '../../store/calendars.js'

const limit = pLimit(1)

Expand Down Expand Up @@ -64,7 +65,8 @@ export default {
}
},
computed: {
...mapGetters({
...mapStores(useCalendarsStore),
...mapState(useCalendarsStore, {
serverCalendars: 'sortedCalendarsSubscriptions',
}),
loadingKeyCalendars() {
Expand All @@ -85,11 +87,11 @@ export default {
}, {})

try {
await limit(() => this.$store.dispatch('updateCalendarListOrder', { newOrder }))
await limit(() => this.calendarsStore.updateCalendarListOrder({ newOrder }))
} catch (err) {
showError(this.$t('calendar', 'Could not update calendar order.'))
// Reset calendar list order on error
this.calendars = this.serverCalendars
this.calendars = this.calendarsStore.sortedCalendarsSubscriptions
} finally {
this.disableDragging = false
}
Expand Down
29 changes: 16 additions & 13 deletions src/components/AppNavigation/CalendarList/CalendarListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ import CheckboxBlankCircleOutline from 'vue-material-design-icons/CheckboxBlankC
import Pencil from 'vue-material-design-icons/Pencil.vue'
import Undo from 'vue-material-design-icons/Undo.vue'
import LinkVariant from 'vue-material-design-icons/LinkVariant.vue'
import usePrincipalsStore from '../../../store/principals.js'
import useCalendarsStore from '../../../store/calendars.js'
import { mapStores } from 'pinia'

export default {
name: 'CalendarListItem',
Expand Down Expand Up @@ -115,6 +118,7 @@ export default {
}
},
computed: {
...mapStores(usePrincipalsStore, useCalendarsStore),
/**
* Whether to show the sharing section
*
Expand Down Expand Up @@ -151,18 +155,18 @@ export default {
* @return {boolean}
*/
loadedOwnerPrincipal() {
return this.$store.getters.getPrincipalByUrl(this.calendar.owner) !== undefined
return this.principalsStore.getPrincipalByUrl(this.calendar.owner) !== undefined
},
ownerUserId() {
const principal = this.$store.getters.getPrincipalByUrl(this.calendar.owner)
const principal = this.principalsStore.getPrincipalByUrl(this.calendar.owner)
if (principal) {
return principal.userId
}

return ''
},
ownerDisplayname() {
const principal = this.$store.getters.getPrincipalByUrl(this.calendar.owner)
const principal = this.principalsStore.getPrincipalByUrl(this.calendar.owner)
if (principal) {
return principal.displayname
}
Expand Down Expand Up @@ -206,28 +210,27 @@ export default {
/**
* Toggles the enabled state of this calendar
*/
toggleEnabled() {
this.$store.dispatch('toggleCalendarEnabled', { calendar: this.calendar })
.catch((error) => {
showError(this.$t('calendar', 'An error occurred, unable to change visibility of the calendar.'))
console.error(error)
})
async toggleEnabled() {
try {
await this.calendarsStore.toggleCalendarEnabled({ calendar: this.calendar })
} catch (error) {
showError(this.$t('calendar', 'An error occurred, unable to change visibility of the calendar.'))
console.error(error)
}
},

/**
* Cancels the deletion of a calendar
*/
cancelDeleteCalendar() {
this.$store.dispatch('cancelCalendarDeletion', { calendar: this.calendar })
this.calendarsStore.cancelCalendarDeletion({ calendar: this.calendar })
},

/**
* Open the calendar modal for this calendar item.
*/
showEditModal() {
this.$store.commit('showEditCalendarModal', {
calendarId: this.calendar.id,
})
this.calendarsStore.editCalendarModal = { calendarId: this.calendar.id }
},
},
}
Expand Down
17 changes: 10 additions & 7 deletions src/components/AppNavigation/CalendarList/CalendarListNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ import CalendarCheck from 'vue-material-design-icons/CalendarCheck.vue'
import LinkVariant from 'vue-material-design-icons/LinkVariant.vue'
import Plus from 'vue-material-design-icons/Plus.vue'
import Web from 'vue-material-design-icons/Web.vue'
import { mapState } from 'vuex'
import { mapStores, mapState } from 'pinia'
import useCalendarsStore from '../../../store/calendars.js'
import useSettingsStore from '../../../store/settings.js'

export default {
name: 'CalendarListNew',
Expand Down Expand Up @@ -153,10 +155,11 @@ export default {
}
},
computed: {
...mapState({
canSubscribeLink: state => state.settings.canSubscribeLink,
hasPublicCalendars: state => Boolean(state.settings.publicCalendars),
...mapState(useSettingsStore, {
canSubscribeLink: 'canSubscribeLink',
hasPublicCalendars: store => Boolean(store.publicCalendars),
}),
...mapStores(useCalendarsStore),
},
watch: {
isOpen() {
Expand Down Expand Up @@ -228,7 +231,7 @@ export default {
const displayName = event.target.querySelector('input[type=text]').value

try {
await this.$store.dispatch('appendCalendar', {
await this.calendarsStore.appendCalendar({
displayName,
color: uidToHexColor(displayName),
})
Expand All @@ -254,7 +257,7 @@ export default {
const displayName = event.target.querySelector('input[type=text]').value

try {
await this.$store.dispatch('appendCalendar', {
await this.calendarsStore.appendCalendar({
displayName,
color: uidToHexColor(displayName),
components: ['VEVENT', 'VTODO'],
Expand Down Expand Up @@ -291,7 +294,7 @@ export default {
}

try {
await this.$store.dispatch('appendSubscription', {
await this.calendarsStore.appendSubscription({
displayName: hostname,
color: uidToHexColor(link),
source: link,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ import {

import Download from 'vue-material-design-icons/Download.vue'
import LinkVariant from 'vue-material-design-icons/LinkVariant.vue'
import useCalendarsStore from '../../../store/calendars.js'
import { mapStores } from 'pinia'

export default {
name: 'PublicCalendarListItem',
Expand Down Expand Up @@ -108,6 +110,7 @@ export default {
}
},
computed: {
...mapStores(useCalendarsStore),
/**
* Download url of the calendar
*
Expand Down Expand Up @@ -177,9 +180,10 @@ export default {
}, 2000)
}
},
toggleEnabled() {
this.$store.commit('toggleCalendarEnabled', {
async toggleEnabled() {
await this.calendarsStore.toggleCalendarEnabled({
calendar: this.calendar,
updateDav: false,
})
},
},
Expand Down
Loading

0 comments on commit 8b5c9f4

Please sign in to comment.