You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. import _ from 'lodash'
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. import pathify from 'vuex-pathify' // eslint-disable-line import/no-duplicates
  5. import { make } from 'vuex-pathify' // eslint-disable-line import/no-duplicates
  6. import page from './page'
  7. import site from './site'
  8. import user from './user'
  9. /* global WIKI */
  10. Vue.use(Vuex)
  11. const state = {
  12. loadingStack: [],
  13. notification: {
  14. message: '',
  15. style: 'primary',
  16. icon: 'cached',
  17. isActive: false
  18. }
  19. }
  20. export default new Vuex.Store({
  21. strict: process.env.NODE_ENV !== 'production',
  22. plugins: [
  23. pathify.plugin
  24. ],
  25. state,
  26. getters: {
  27. isLoading: state => { return state.loadingStack.length > 0 }
  28. },
  29. mutations: {
  30. ...make.mutations(state),
  31. loadingStart (state, stackName) {
  32. state.loadingStack = _.union(state.loadingStack, [stackName])
  33. },
  34. loadingStop (state, stackName) {
  35. state.loadingStack = _.without(state.loadingStack, stackName)
  36. },
  37. showNotification (state, opts) {
  38. state.notification = _.defaults(opts, {
  39. message: '',
  40. style: 'primary',
  41. icon: 'cached',
  42. isActive: true
  43. })
  44. },
  45. updateNotificationState (state, newState) {
  46. state.notification.isActive = newState
  47. },
  48. pushGraphError (state, err) {
  49. WIKI.$store.commit('showNotification', {
  50. style: 'red',
  51. message: _.get(err, 'graphQLErrors[0].message', err.message),
  52. icon: 'warning'
  53. })
  54. }
  55. },
  56. actions: { },
  57. modules: {
  58. page,
  59. site,
  60. user
  61. }
  62. })