Skip to content

Commit

Permalink
chore: migrate from Vuex to Pinia
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory V <scratchx@gmx.com>
  • Loading branch information
GVodyanov authored and st3iny committed Jun 24, 2024
1 parent 8ef6476 commit 7de1908
Show file tree
Hide file tree
Showing 81 changed files with 5,131 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'

Check warning on line 61 in src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue#L60-L61

Added lines #L60 - L61 were not covered by tests
export default {
name: 'AppNavigationHeaderDatePicker',
Expand All @@ -81,12 +83,13 @@ export default {
}
},
computed: {
...mapState({
locale: (state) => state.settings.momentLocale,
...mapStores(useWidgetStore),
...mapState(useSettingsStore, {

Check warning on line 87 in src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue#L87

Added line #L87 was not covered by tests
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

Check warning on line 142 in src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue#L142

Added line #L142 was not covered by tests
}
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) })

Check warning on line 196 in src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppNavigationHeader/AppNavigationHeaderDatePicker.vue#L196

Added line #L196 was not covered by tests
} 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'

Check warning on line 56 in src/components/AppNavigation/AppointmentConfigList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppointmentConfigList.vue#L56

Added line #L56 was not covered by tests
import useCalendarsStore from '../../store/calendars.js'
import useSettingsStore from '../../store/settings.js'

Check warning on line 58 in src/components/AppNavigation/AppointmentConfigList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppointmentConfigList.vue#L58

Added line #L58 was not covered by tests
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,
}),

Check warning on line 80 in src/components/AppNavigation/AppointmentConfigList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppointmentConfigList.vue#L80

Added line #L80 was not covered by tests
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,

Check warning on line 84 in src/components/AppNavigation/AppointmentConfigList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppointmentConfigList.vue#L84

Added line #L84 was not covered by tests
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 }))

Check warning on line 90 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L90

Added line #L90 was not covered by tests
} 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)

Check warning on line 161 in src/components/AppNavigation/CalendarList/CalendarListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/CalendarListItem.vue#L161

Added line #L161 was not covered by tests
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() {

Check warning on line 213 in src/components/AppNavigation/CalendarList/CalendarListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/CalendarListItem.vue#L213

Added line #L213 was not covered by tests
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'

Check warning on line 120 in src/components/AppNavigation/CalendarList/CalendarListNew.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/CalendarListNew.vue#L120

Added line #L120 was not covered by tests
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),

Check warning on line 160 in src/components/AppNavigation/CalendarList/CalendarListNew.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/CalendarListNew.vue#L159-L160

Added lines #L159 - L160 were not covered by tests
}),
...mapStores(useCalendarsStore),

Check warning on line 162 in src/components/AppNavigation/CalendarList/CalendarListNew.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/CalendarListNew.vue#L162

Added line #L162 was not covered by tests
},
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({

Check warning on line 260 in src/components/AppNavigation/CalendarList/CalendarListNew.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/CalendarListNew.vue#L260

Added line #L260 was not covered by tests
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'

Check warning on line 81 in src/components/AppNavigation/CalendarList/PublicCalendarListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/PublicCalendarListItem.vue#L80-L81

Added lines #L80 - L81 were not covered by tests
export default {
name: 'PublicCalendarListItem',
Expand Down Expand Up @@ -108,6 +110,7 @@ export default {
}
},
computed: {
...mapStores(useCalendarsStore),

Check warning on line 113 in src/components/AppNavigation/CalendarList/PublicCalendarListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/PublicCalendarListItem.vue#L113

Added line #L113 was not covered by tests
/**
* Download url of the calendar
*
Expand Down Expand Up @@ -177,9 +180,10 @@ export default {
}, 2000)
}
},
toggleEnabled() {
this.$store.commit('toggleCalendarEnabled', {
async toggleEnabled() {

Check warning on line 183 in src/components/AppNavigation/CalendarList/PublicCalendarListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList/PublicCalendarListItem.vue#L183

Added line #L183 was not covered by tests
await this.calendarsStore.toggleCalendarEnabled({
calendar: this.calendar,
updateDav: false,
})
},
},
Expand Down
Loading

0 comments on commit 7de1908

Please sign in to comment.