2018-03-25 02:35:47 +00:00
|
|
|
import _ from 'lodash'
|
2017-05-21 20:43:58 +00:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
2018-07-22 04:29:39 +00:00
|
|
|
import pathify from 'vuex-pathify' // eslint-disable-line import/no-duplicates
|
|
|
|
import { make } from 'vuex-pathify' // eslint-disable-line import/no-duplicates
|
2017-05-21 20:43:58 +00:00
|
|
|
|
2018-10-29 02:09:58 +00:00
|
|
|
import page from './page'
|
2018-08-04 21:27:55 +00:00
|
|
|
import site from './site'
|
2018-12-03 02:42:43 +00:00
|
|
|
import user from './user'
|
2018-08-04 21:27:55 +00:00
|
|
|
|
2019-08-04 20:31:13 +00:00
|
|
|
/* global WIKI */
|
|
|
|
|
2017-05-21 20:43:58 +00:00
|
|
|
Vue.use(Vuex)
|
|
|
|
|
2018-07-22 04:29:39 +00:00
|
|
|
const state = {
|
|
|
|
loadingStack: [],
|
|
|
|
notification: {
|
|
|
|
message: '',
|
|
|
|
style: 'primary',
|
|
|
|
icon: 'cached',
|
|
|
|
isActive: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-21 20:43:58 +00:00
|
|
|
export default new Vuex.Store({
|
2018-06-10 00:11:00 +00:00
|
|
|
strict: process.env.NODE_ENV !== 'production',
|
2018-07-15 23:16:19 +00:00
|
|
|
plugins: [
|
|
|
|
pathify.plugin
|
|
|
|
],
|
2018-07-22 04:29:39 +00:00
|
|
|
state,
|
2018-03-25 02:35:47 +00:00
|
|
|
getters: {
|
|
|
|
isLoading: state => { return state.loadingStack.length > 0 }
|
2017-05-21 20:43:58 +00:00
|
|
|
},
|
2018-03-25 02:35:47 +00:00
|
|
|
mutations: {
|
2018-07-22 04:29:39 +00:00
|
|
|
...make.mutations(state),
|
2019-09-08 16:39:05 +00:00
|
|
|
loadingStart (st, stackName) {
|
|
|
|
st.loadingStack = _.union(st.loadingStack, [stackName])
|
2018-03-25 02:35:47 +00:00
|
|
|
},
|
2019-09-08 16:39:05 +00:00
|
|
|
loadingStop (st, stackName) {
|
|
|
|
st.loadingStack = _.without(st.loadingStack, stackName)
|
2018-03-25 02:35:47 +00:00
|
|
|
},
|
2019-09-08 16:39:05 +00:00
|
|
|
showNotification (st, opts) {
|
|
|
|
st.notification = _.defaults(opts, {
|
2018-03-25 02:35:47 +00:00
|
|
|
message: '',
|
|
|
|
style: 'primary',
|
|
|
|
icon: 'cached',
|
|
|
|
isActive: true
|
|
|
|
})
|
|
|
|
},
|
2019-09-08 16:39:05 +00:00
|
|
|
updateNotificationState (st, newState) {
|
|
|
|
st.notification.isActive = newState
|
2019-01-13 03:33:30 +00:00
|
|
|
},
|
2019-09-08 16:39:05 +00:00
|
|
|
pushGraphError (st, err) {
|
2019-01-13 03:33:30 +00:00
|
|
|
WIKI.$store.commit('showNotification', {
|
|
|
|
style: 'red',
|
|
|
|
message: _.get(err, 'graphQLErrors[0].message', err.message),
|
|
|
|
icon: 'warning'
|
|
|
|
})
|
2018-03-25 02:35:47 +00:00
|
|
|
}
|
2017-05-21 20:43:58 +00:00
|
|
|
},
|
2018-03-25 02:35:47 +00:00
|
|
|
actions: { },
|
2018-08-04 21:27:55 +00:00
|
|
|
modules: {
|
2018-10-29 02:09:58 +00:00
|
|
|
page,
|
2018-12-03 02:42:43 +00:00
|
|
|
site,
|
|
|
|
user
|
2018-08-04 21:27:55 +00:00
|
|
|
}
|
2017-05-21 20:43:58 +00:00
|
|
|
})
|