Skip to content

Commit 857477c

Browse files
committed
refactor: migrate from vuex to pinia
Signed-off-by: fenn-cs <[email protected]>
1 parent 607e63e commit 857477c

4 files changed

Lines changed: 24 additions & 43 deletions

File tree

core/src/store/index.js

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

core/src/store/unified-search-external-filters.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,18 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
const state = {
23-
externalFilters: [],
24-
}
22+
import { defineStore } from 'pinia'
2523

26-
const mutations = {
27-
registerExternalFilter(state, { id, label, callback, icon }) {
28-
state.externalFilters.push({ id, name: label, callback, icon, isPluginFilter: true })
29-
},
30-
}
24+
export const useSearchStore = defineStore({
25+
id: 'search',
3126

32-
const actions = {
33-
registerExternalFilter({ commit }, { id, label, callback, icon }) {
34-
commit('registerExternalFilter', { id, label, callback, icon })
35-
},
36-
}
27+
state: () => ({
28+
externalFilters: [],
29+
}),
3730

38-
export default {
39-
state,
40-
mutations,
41-
actions,
42-
}
31+
actions: {
32+
registerExternalFilter({ id, appId, label, callback, icon }) {
33+
this.externalFilters.push({ id, appId, name: label, callback, icon, isPluginFilter: true })
34+
},
35+
},
36+
})

core/src/unified-search.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import { getLoggerBuilder } from '@nextcloud/logger'
2424
import { getRequestToken } from '@nextcloud/auth'
2525
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
26+
import { createPinia, PiniaVuePlugin } from 'pinia'
2627
import Vue from 'vue'
2728

2829
import UnifiedSearch from './views/UnifiedSearch.vue'
29-
import store from '../src/store/index.js'
30+
import { useSearchStore } from '../src/store/unified-search-external-filters.js'
3031

3132
// eslint-disable-next-line camelcase
3233
__webpack_nonce__ = btoa(getRequestToken())
@@ -51,21 +52,19 @@ Vue.mixin({
5152
// Register the add/register filter action API globally
5253
window.OCP = window.OCP || {}
5354
window.OCP.UnifiedSearch = {
54-
registerFilterAction: ({ id, name, label, callback, icon }) => {
55-
store.dispatch('registerExternalFilter', {
56-
id,
57-
name,
58-
label,
59-
icon,
60-
callback,
61-
})
55+
registerFilterAction: ({ id, appId, name, label, callback, icon }) => {
56+
const searchStore = useSearchStore()
57+
searchStore.registerExternalFilter({ id, appId, name, label, callback, icon })
6258
},
6359
}
6460

61+
Vue.use(PiniaVuePlugin)
62+
const pinia = createPinia()
63+
6564
export default new Vue({
6665
el: '#unified-search',
66+
pinia,
6767
// eslint-disable-next-line vue/match-component-file-name
6868
name: 'UnifiedSearchRoot',
69-
store,
7069
render: h => h(UnifiedSearch),
7170
})

core/src/views/UnifiedSearchModal.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ import SearchResult from '../components/UnifiedSearch/SearchResult.vue'
154154
import debounce from 'debounce'
155155
import { emit, subscribe } from '@nextcloud/event-bus'
156156
import { useBrowserLocation } from '@vueuse/core'
157-
import { mapState } from 'vuex'
158157
import { getProviders, search as unifiedSearch, getContacts } from '../services/UnifiedSearchService.js'
158+
import { useSearchStore } from '../store/unified-search-external-filters.js'
159159
160160
export default {
161161
name: 'UnifiedSearchModal',
@@ -190,8 +190,10 @@ export default {
190190
* Reactive version of window.location
191191
*/
192192
const currentLocation = useBrowserLocation()
193+
const searchStore = useSearchStore()
193194
return {
194195
currentLocation,
196+
externalFilters: searchStore.externalFilters,
195197
}
196198
},
197199
data() {
@@ -220,9 +222,6 @@ export default {
220222
},
221223
222224
computed: {
223-
...mapState({
224-
externalFilters: state => state.search.externalFilters,
225-
}),
226225
userContacts() {
227226
return this.contacts
228227
},

0 commit comments

Comments
 (0)