Skip to content

Commit

Permalink
refactor: migrate from vuex to pinia
Browse files Browse the repository at this point in the history
Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Mar 4, 2024
1 parent 607e63e commit 857477c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 43 deletions.
11 changes: 0 additions & 11 deletions core/src/store/index.js

This file was deleted.

30 changes: 12 additions & 18 deletions core/src/store/unified-search-external-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
const state = {
externalFilters: [],
}
import { defineStore } from 'pinia'

const mutations = {
registerExternalFilter(state, { id, label, callback, icon }) {
state.externalFilters.push({ id, name: label, callback, icon, isPluginFilter: true })
},
}
export const useSearchStore = defineStore({
id: 'search',

const actions = {
registerExternalFilter({ commit }, { id, label, callback, icon }) {
commit('registerExternalFilter', { id, label, callback, icon })
},
}
state: () => ({
externalFilters: [],
}),

export default {
state,
mutations,
actions,
}
actions: {
registerExternalFilter({ id, appId, label, callback, icon }) {
this.externalFilters.push({ id, appId, name: label, callback, icon, isPluginFilter: true })
},
},
})
19 changes: 9 additions & 10 deletions core/src/unified-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import { getLoggerBuilder } from '@nextcloud/logger'
import { getRequestToken } from '@nextcloud/auth'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
import { createPinia, PiniaVuePlugin } from 'pinia'
import Vue from 'vue'

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

// eslint-disable-next-line camelcase
__webpack_nonce__ = btoa(getRequestToken())
Expand All @@ -51,21 +52,19 @@ Vue.mixin({
// Register the add/register filter action API globally
window.OCP = window.OCP || {}
window.OCP.UnifiedSearch = {
registerFilterAction: ({ id, name, label, callback, icon }) => {
store.dispatch('registerExternalFilter', {
id,
name,
label,
icon,
callback,
})
registerFilterAction: ({ id, appId, name, label, callback, icon }) => {
const searchStore = useSearchStore()
searchStore.registerExternalFilter({ id, appId, name, label, callback, icon })
},
}

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

export default new Vue({
el: '#unified-search',
pinia,
// eslint-disable-next-line vue/match-component-file-name
name: 'UnifiedSearchRoot',
store,
render: h => h(UnifiedSearch),
})
7 changes: 3 additions & 4 deletions core/src/views/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ import SearchResult from '../components/UnifiedSearch/SearchResult.vue'
import debounce from 'debounce'
import { emit, subscribe } from '@nextcloud/event-bus'
import { useBrowserLocation } from '@vueuse/core'
import { mapState } from 'vuex'
import { getProviders, search as unifiedSearch, getContacts } from '../services/UnifiedSearchService.js'
import { useSearchStore } from '../store/unified-search-external-filters.js'
export default {
name: 'UnifiedSearchModal',
Expand Down Expand Up @@ -190,8 +190,10 @@ export default {
* Reactive version of window.location
*/
const currentLocation = useBrowserLocation()
const searchStore = useSearchStore()
return {
currentLocation,
externalFilters: searchStore.externalFilters,
}
},
data() {
Expand Down Expand Up @@ -220,9 +222,6 @@ export default {
},
computed: {
...mapState({
externalFilters: state => state.search.externalFilters,
}),
userContacts() {
return this.contacts
},
Expand Down

0 comments on commit 857477c

Please sign in to comment.