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.

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