Skip to content

Commit 0b11f3b

Browse files
committed
introduce pinia first stores
Signed-off-by: grnd-alt <git@belakkaf.net>
1 parent b86df2a commit 0b11f3b

File tree

11 files changed

+541
-54
lines changed

11 files changed

+541
-54
lines changed

src/App.vue

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
</template>
3131

3232
<script>
33-
import { mapState } from 'vuex'
33+
import { storeToRefs } from 'pinia'
34+
import { useBoardStore } from './stores/board.js'
3435
import AppNavigation from './components/navigation/AppNavigation.vue'
3536
import KeyboardShortcuts from './components/KeyboardShortcuts.vue'
3637
import { NcModal, NcContent, NcAppContent, isMobile } from '@nextcloud/vue'
@@ -57,6 +58,17 @@ export default {
5758
boardApi,
5859
}
5960
},
61+
setup() {
62+
const boardStore = useBoardStore()
63+
const { navShown, sidebarShown: sidebarShownState, currentBoard } = storeToRefs(boardStore)
64+
65+
return {
66+
boardStore,
67+
navShown,
68+
sidebarShownState,
69+
currentBoard,
70+
}
71+
},
6072
data() {
6173
return {
6274
addButton: {
@@ -77,11 +89,6 @@ export default {
7789
}
7890
},
7991
computed: {
80-
...mapState({
81-
navShown: state => state.navShown,
82-
sidebarShownState: state => state.sidebarShown,
83-
currentBoard: state => state.currentBoard,
84-
}),
8592
// TODO: properly handle sidebar showing for route subview and board sidebar
8693
sidebarRouterView() {
8794
// console.log(this.$route)
@@ -92,19 +99,19 @@ export default {
9299
},
93100
cardDetailsInModal: {
94101
get() {
95-
return this.$store.getters.config('cardDetailsInModal')
102+
return this.boardStore.getConfig('cardDetailsInModal')
96103
},
97104
set(newValue) {
98-
this.$store.dispatch('setConfig', { cardDetailsInModal: newValue })
105+
this.boardStore.setConfig({ cardDetailsInModal: newValue })
99106
},
100107
},
101108
},
102109
created() {
103110
const initialState = loadState('deck', 'initialBoards', null)
104111
if (initialState !== null) {
105-
this.$store.dispatch('loadBoards')
112+
this.boardStore.loadBoards()
106113
}
107-
this.$store.dispatch('loadSharees')
114+
this.boardStore.loadSharees()
108115
},
109116
mounted() {
110117
// Redirect to cleaner URL (without /index.php) if RewriteBase is enabled
@@ -115,7 +122,7 @@ export default {
115122
emit('toggle-navigation', { open: !this.isMobile && this.navShown, _initial: true })
116123
this.$nextTick(() => {
117124
subscribe('navigation-toggled', (navState) => {
118-
this.$store.dispatch('toggleNav', navState.open)
125+
this.boardStore.toggleNav(navState.open)
119126
})
120127
})
121128
},

src/components/card/CardSidebar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export default {
149149
currentBoard: (state) => state.currentBoard,
150150
hasCardSaveError: (state) => state.hasCardSaveError,
151151
}),
152-
...mapGetters(['canEdit', 'assignables', 'cardActions', 'stackById']),
152+
...mapGetters(['canEdit', 'assignables', 'stackById']),
153153
currentCard() {
154154
return this.$store.getters.cardById(this.id)
155155
},

src/components/cards/CardMenuEntries.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { showUndo } from '@nextcloud/dialogs'
7373
7474
import '@nextcloud/dialogs/style.css'
7575
import { emit } from '@nextcloud/event-bus'
76+
import { useActionsStore } from '../../stores/actions'
7677
7778
export default {
7879
name: 'CardMenuEntries',
@@ -88,6 +89,12 @@ export default {
8889
},
8990
},
9091
emits: ['edit-title'],
92+
setup() {
93+
const actionsStore = useActionsStore()
94+
return {
95+
cardActions: actionsStore.cardActions,
96+
}
97+
},
9198
data() {
9299
return {
93100
modalShow: false,
@@ -100,7 +107,6 @@ export default {
100107
...mapGetters([
101108
'isArchived',
102109
'boards',
103-
'cardActions',
104110
'stackById',
105111
'boardById',
106112
]),

src/components/navigation/AppNavigation.vue

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
</template>
6565

6666
<script>
67-
import { mapGetters } from 'vuex'
6867
import ClickOutside from 'vue-click-outside'
6968
import { NcAppNavigation, NcAppNavigationItem } from '@nextcloud/vue'
7069
import AppNavigationAddBoard from './AppNavigationAddBoard.vue'
@@ -81,6 +80,8 @@ import AppNavigationImportBoard from './AppNavigationImportBoard.vue'
8180
import DeckAppSettings from '../DeckAppSettings.vue'
8281
import IconCog from 'vue-material-design-icons/CogOutline.vue'
8382
import { getCurrentUser } from '@nextcloud/auth'
83+
import { useBoardStore } from '../../stores/board'
84+
import { storeToRefs } from 'pinia'
8485
8586
const canCreateState = loadState('deck', 'canCreate')
8687
@@ -110,6 +111,17 @@ export default {
110111
default: false,
111112
},
112113
},
114+
setup() {
115+
const boardStore = useBoardStore()
116+
const { noneArchivedBoards, archivedBoards, sharedBoards } = storeToRefs(boardStore)
117+
118+
return {
119+
boardStore,
120+
noneArchivedBoards,
121+
archivedBoards,
122+
sharedBoards,
123+
}
124+
},
113125
data() {
114126
return {
115127
opened: false,
@@ -122,36 +134,31 @@ export default {
122134
}
123135
},
124136
computed: {
125-
...mapGetters([
126-
'noneArchivedBoards',
127-
'archivedBoards',
128-
'sharedBoards',
129-
]),
130137
isAdmin() {
131138
return !!getCurrentUser()?.isAdmin
132139
},
133140
cardDetailsInModal: {
134141
get() {
135-
return this.$store.getters.config('cardDetailsInModal')
142+
return this.boardStore.cardDetailsInModal
136143
},
137144
set(newValue) {
138-
this.$store.dispatch('setConfig', { cardDetailsInModal: newValue })
145+
this.boardStore.setConfig({ key: 'cardDetailsInModal', value: newValue })
139146
},
140147
},
141148
cardIdBadge: {
142149
get() {
143-
return this.$store.getters.config('cardIdBadge')
150+
return this.boardStore.cardIdBadge
144151
},
145152
set(newValue) {
146-
this.$store.dispatch('setConfig', { cardIdBadge: newValue })
153+
this.boardStore.setConfig({ key: 'cardIdBadge', value: newValue })
147154
},
148155
},
149156
configCalendar: {
150157
get() {
151-
return this.$store.getters.config('calendar')
158+
return this.boardStore.configCalendar
152159
},
153160
set(newValue) {
154-
this.$store.dispatch('setConfig', { calendar: newValue })
161+
this.boardStore.setConfig({ key: 'calendar', value: newValue })
155162
},
156163
},
157164
},

src/components/navigation/AppNavigationAddBoard.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import { NcButton, NcColorPicker, NcAppNavigationItem, NcLoadingIcon, NcTextField } from '@nextcloud/vue'
4646
import CheckIcon from 'vue-material-design-icons/Check.vue'
4747
import CloseIcon from 'vue-material-design-icons/Close.vue'
48+
import { useBoardStore } from '../../stores/board'
4849
4950
/**
5051
*
@@ -62,6 +63,12 @@ export default {
6263
components: { NcButton, NcColorPicker, NcAppNavigationItem, NcLoadingIcon, NcTextField, CheckIcon, CloseIcon },
6364
directives: {},
6465
props: {},
66+
setup () {
67+
const boardStore = useBoardStore()
68+
return {
69+
boardStore,
70+
}
71+
},
6572
data() {
6673
return {
6774
value: '',
@@ -81,7 +88,7 @@ export default {
8188
async createBoard(e) {
8289
this.loading = true
8390
const title = this.value.trim()
84-
await this.$store.dispatch('createBoard', {
91+
await this.boardStore.createBoard({
8592
title,
8693
color: this.color.substring(1),
8794
})

src/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55
import Vue from 'vue'
6+
import { pinia } from './stores/index.js'
67
import App from './App.vue'
78
import router from './router.js'
89
import storeFactory from './store/main.js'
@@ -14,6 +15,7 @@ import ClickOutside from 'vue-click-outside'
1415
import './shared-init.js'
1516
import './models/index.js'
1617
import { initSessions } from './sessions.js'
18+
import { useActionsStore } from './stores/actions.js'
1719

1820
// the server snap.js conflicts with vertical scrolling so we disable it
1921
document.body.setAttribute('data-snap-ignore', 'true')
@@ -48,6 +50,7 @@ new Vue({
4850
name: 'Deck',
4951
router,
5052
store,
53+
pinia,
5154
data() {
5255
return {
5356
time: Date.now(),
@@ -115,5 +118,6 @@ window.OCA.Deck.registerCardAction = ({ label, callback, icon }) => {
115118
callback,
116119
icon,
117120
}
118-
store.dispatch('addCardAction', cardAction)
121+
const actionsStore = useActionsStore()
122+
actionsStore.addCardAction(cardAction)
119123
}

src/store/actions.js

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

src/store/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Vuex from 'vuex'
1111
import axios from '@nextcloud/axios'
1212
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
1313
import { BoardApi } from '../services/BoardApi.js'
14-
import actions from './actions.js'
1514
import stackModuleFactory from './stack.js'
1615
import cardModuleFactory from './card.js'
1716
import comment from './comment.js'
@@ -35,7 +34,6 @@ export const BOARD_FILTERS = {
3534
export default function storeFactory() {
3635
return new Vuex.Store({
3736
modules: {
38-
actions,
3937
stack: stackModuleFactory(),
4038
card: cardModuleFactory(),
4139
comment,

src/stores/actions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { defineStore } from "pinia";
2+
3+
4+
export const useActionsStore = defineStore('actions',
5+
{
6+
state: () => ({
7+
actions: {
8+
card: [],
9+
}
10+
}),
11+
getters: {
12+
cardActions: (state) => state.actions.card,
13+
},
14+
actions: {
15+
async addCardAction(action) {
16+
this.actions.card.push(action)
17+
},
18+
},
19+
})
20+

0 commit comments

Comments
 (0)