wikijs-fork/client/store/index.js
rbtprograms 0f9ddf1e5d fix: Switch converted to Object Literal (#940)
* updating a switch into object literal and fixed a couple linter errors

* added a comment about weird formatting

* style: use lodash get

* fix: pass eslint + puglint + jest
2019-08-04 16:31:13 -04:00

68 lines
1.5 KiB
JavaScript

import _ from 'lodash'
import Vue from 'vue'
import Vuex from 'vuex'
import pathify from 'vuex-pathify' // eslint-disable-line import/no-duplicates
import { make } from 'vuex-pathify' // eslint-disable-line import/no-duplicates
import page from './page'
import site from './site'
import user from './user'
/* global WIKI */
Vue.use(Vuex)
const state = {
loadingStack: [],
notification: {
message: '',
style: 'primary',
icon: 'cached',
isActive: false
}
}
export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
plugins: [
pathify.plugin
],
state,
getters: {
isLoading: state => { return state.loadingStack.length > 0 }
},
mutations: {
...make.mutations(state),
loadingStart (state, stackName) {
state.loadingStack = _.union(state.loadingStack, [stackName])
},
loadingStop (state, stackName) {
state.loadingStack = _.without(state.loadingStack, stackName)
},
showNotification (state, opts) {
state.notification = _.defaults(opts, {
message: '',
style: 'primary',
icon: 'cached',
isActive: true
})
},
updateNotificationState (state, newState) {
state.notification.isActive = newState
},
pushGraphError (state, err) {
WIKI.$store.commit('showNotification', {
style: 'red',
message: _.get(err, 'graphQLErrors[0].message', err.message),
icon: 'warning'
})
}
},
actions: { },
modules: {
page,
site,
user
}
})