index.js 1.47 KB
Newer Older
1
import _ from 'lodash'
2 3
import Vue from 'vue'
import Vuex from 'vuex'
NGPixel's avatar
NGPixel committed
4 5
import pathify from 'vuex-pathify' // eslint-disable-line import/no-duplicates
import { make } from 'vuex-pathify' // eslint-disable-line import/no-duplicates
6

7
import page from './page'
8
import site from './site'
9
import user from './user'
10

11 12
/* global WIKI */

13 14
Vue.use(Vuex)

NGPixel's avatar
NGPixel committed
15 16 17 18 19 20 21 22 23 24
const state = {
  loadingStack: [],
  notification: {
    message: '',
    style: 'primary',
    icon: 'cached',
    isActive: false
  }
}

25
export default new Vuex.Store({
NGPixel's avatar
NGPixel committed
26
  strict: process.env.NODE_ENV !== 'production',
NGPixel's avatar
NGPixel committed
27 28 29
  plugins: [
    pathify.plugin
  ],
NGPixel's avatar
NGPixel committed
30
  state,
31 32
  getters: {
    isLoading: state => { return state.loadingStack.length > 0 }
33
  },
34
  mutations: {
NGPixel's avatar
NGPixel committed
35
    ...make.mutations(state),
Nick's avatar
Nick committed
36 37
    loadingStart (st, stackName) {
      st.loadingStack = _.union(st.loadingStack, [stackName])
38
    },
Nick's avatar
Nick committed
39 40
    loadingStop (st, stackName) {
      st.loadingStack = _.without(st.loadingStack, stackName)
41
    },
Nick's avatar
Nick committed
42 43
    showNotification (st, opts) {
      st.notification = _.defaults(opts, {
44 45 46 47 48 49
        message: '',
        style: 'primary',
        icon: 'cached',
        isActive: true
      })
    },
Nick's avatar
Nick committed
50 51
    updateNotificationState (st, newState) {
      st.notification.isActive = newState
52
    },
Nick's avatar
Nick committed
53
    pushGraphError (st, err) {
54 55 56
      WIKI.$store.commit('showNotification', {
        style: 'red',
        message: _.get(err, 'graphQLErrors[0].message', err.message),
57
        icon: 'alert'
58
      })
59
    }
60
  },
61
  actions: { },
62
  modules: {
63
    page,
64 65
    site,
    user
66
  }
67
})