Skip to content

Commit 393a7e8

Browse files
authored
Merge pull request #8128 from nextcloud/refactor/pinia-migration-dashboardStore
refactor(pinia): migrate dashboard store
2 parents b0b49bb + 974a642 commit 393a7e8

6 files changed

Lines changed: 53 additions & 61 deletions

File tree

src/init-dashboard.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,59 @@ const getAsyncImports = async () => {
1717
}
1818

1919
const { default: Vue } = await import('vue')
20+
const { createPinia, PiniaVuePlugin } = await import('pinia')
2021
const { default: Vuex } = await import('vuex')
21-
const { default: dashboard } = await import('./store/dashboard.js')
2222

2323
Vue.prototype.t = t
2424
Vue.prototype.n = n
2525
Vue.prototype.OC = OC
26+
const pinia = createPinia()
27+
Vue.use(PiniaVuePlugin)
2628
Vue.use(Vuex)
27-
2829
const store = new Vuex.Store({
29-
modules: {
30-
dashboard,
31-
},
3230
strict: debug,
3331
})
3432

3533
_imports = {
36-
store, Vue,
34+
pinia, Vue, store,
3735
}
3836

3937
return _imports
4038
}
4139

4240
document.addEventListener('DOMContentLoaded', () => {
4341
OCA.Dashboard.register('deck', async (el) => {
44-
const { Vue, store } = await getAsyncImports()
42+
const { Vue, pinia, store } = await getAsyncImports()
4543
const { default: DashboardUpcoming } = await import('./views/DashboardUpcoming.vue')
4644

4745
const View = Vue.extend(DashboardUpcoming)
4846
const vm = new View({
4947
propsData: {},
48+
pinia,
5049
store,
5150
}).$mount(el)
5251
return vm
5352
})
5453

5554
OCA.Dashboard.register('deckToday', async (el) => {
56-
const { Vue, store } = await getAsyncImports()
55+
const { Vue, pinia, store } = await getAsyncImports()
5756
const { default: DashboardToday } = await import('./views/DashboardToday.vue')
5857
const View = Vue.extend(DashboardToday)
5958
const vm = new View({
6059
propsData: {},
60+
pinia,
6161
store,
6262
}).$mount(el)
6363
return vm
6464
})
6565

6666
OCA.Dashboard.register('deckTomorrow', async (el) => {
67-
const { Vue, store } = await getAsyncImports()
67+
const { Vue, pinia, store } = await getAsyncImports()
6868
const { default: DashboardTomorrow } = await import('./views/DashboardTomorrow.vue')
6969
const View = Vue.extend(DashboardTomorrow)
7070
const vm = new View({
7171
propsData: {},
72+
pinia,
7273
store,
7374
}).$mount(el)
7475
return vm

src/store/dashboard.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/stores/dashboard.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { defineStore } from 'pinia'
7+
import { OverviewApi } from '../services/OverviewApi.js'
8+
9+
const apiClient = new OverviewApi()
10+
11+
export const useDashboardStore = defineStore('dashboard', {
12+
state: () => ({
13+
assignedCards: [],
14+
}),
15+
actions: {
16+
async loadUpcoming() {
17+
const upcommingCards = await apiClient.get('upcoming')
18+
this.assignedCards = upcommingCards
19+
},
20+
},
21+
})

src/views/DashboardToday.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
<script>
2222
import { NcDashboardWidget } from '@nextcloud/vue'
23-
import { mapGetters } from 'vuex'
2423
import Card from '../components/dashboard/Card.vue'
2524
import { generateUrl } from '@nextcloud/router'
25+
import { useDashboardStore } from '../stores/dashboard.js'
26+
import { mapActions, mapState } from 'pinia'
2627
2728
export default {
2829
name: 'DashboardToday',
@@ -36,11 +37,9 @@ export default {
3637
}
3738
},
3839
computed: {
39-
...mapGetters([
40-
'assignedCardsDashboard',
41-
]),
40+
...mapState(useDashboardStore, ['assignedCards']),
4241
cards() {
43-
const list = [...this.assignedCardsDashboard.today || []]
42+
const list = [...this.assignedCards.today || []]
4443
list.sort((a, b) => {
4544
return (new Date(a.duedate)).getTime() - (new Date(b.duedate)).getTime()
4645
})
@@ -52,10 +51,13 @@ export default {
5251
},
5352
beforeMount() {
5453
this.loading = true
55-
this.$store.dispatch('loadUpcoming').then(() => {
54+
this.loadUpcoming().then(() => {
5655
this.loading = false
5756
})
5857
},
58+
methods: {
59+
...mapActions(useDashboardStore, ['loadUpcoming']),
60+
},
5961
}
6062
</script>
6163

src/views/DashboardTomorrow.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
<script>
2222
import { NcDashboardWidget } from '@nextcloud/vue'
23-
import { mapGetters } from 'vuex'
2423
import Card from '../components/dashboard/Card.vue'
2524
import { generateUrl } from '@nextcloud/router'
25+
import { useDashboardStore } from '../stores/dashboard.js'
26+
import { mapActions, mapState } from 'pinia'
2627
2728
export default {
2829
name: 'DashboardTomorrow',
@@ -36,11 +37,9 @@ export default {
3637
}
3738
},
3839
computed: {
39-
...mapGetters([
40-
'assignedCardsDashboard',
41-
]),
40+
...mapState(useDashboardStore, ['assignedCards']),
4241
cards() {
43-
const list = [...this.assignedCardsDashboard.tomorrow || []]
42+
const list = [...this.assignedCards.tomorrow || []]
4443
list.sort((a, b) => {
4544
return (new Date(a.duedate)).getTime() - (new Date(b.duedate)).getTime()
4645
})
@@ -52,10 +51,13 @@ export default {
5251
},
5352
beforeMount() {
5453
this.loading = true
55-
this.$store.dispatch('loadUpcoming').then(() => {
54+
this.loadUpcoming().then(() => {
5655
this.loading = false
5756
})
5857
},
58+
methods: {
59+
...mapActions(useDashboardStore, ['loadUpcoming']),
60+
},
5961
}
6062
</script>
6163

src/views/DashboardUpcoming.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
<script>
3434
import PlusIcon from 'vue-material-design-icons/Plus.vue'
3535
import { NcButton, NcDashboardWidget, NcModal } from '@nextcloud/vue'
36-
import { mapGetters } from 'vuex'
3736
import Card from '../components/dashboard/Card.vue'
3837
import { generateUrl } from '@nextcloud/router'
3938
import CreateNewCardCustomPicker from './CreateNewCardCustomPicker.vue'
39+
import { useDashboardStore } from '../stores/dashboard.js'
40+
import { mapActions, mapState } from 'pinia'
4041
4142
export default {
4243
name: 'DashboardUpcoming',
@@ -55,11 +56,9 @@ export default {
5556
}
5657
},
5758
computed: {
58-
...mapGetters([
59-
'assignedCardsDashboard',
60-
]),
59+
...mapState(useDashboardStore, ['assignedCards']),
6160
cards() {
62-
const list = Object.values(this.assignedCardsDashboard).flat()
61+
const list = Object.values(this.assignedCards).flat()
6362
.filter((card) => {
6463
return card.duedate !== null
6564
})
@@ -74,11 +73,12 @@ export default {
7473
},
7574
beforeMount() {
7675
this.loading = true
77-
this.$store.dispatch('loadUpcoming').then(() => {
76+
this.loadUpcoming().then(() => {
7877
this.loading = false
7978
})
8079
},
8180
methods: {
81+
...mapActions(useDashboardStore, ['loadUpcoming']),
8282
toggleAddCardModel() {
8383
this.showAddCardModal = !this.showAddCardModal
8484
},

0 commit comments

Comments
 (0)