Commit 0c62aa49 authored by Joel Collins's avatar Joel Collins
Browse files

Added state mutations

parent f5c59d3a
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -15,7 +15,8 @@ export default new Vuex.Store({
    available: true,
    waiting: false,
    error: '',
    apiConfig: {}
    apiConfig: {},
    apiState: {}
  },

  mutations: {
@@ -38,6 +39,9 @@ export default new Vuex.Store({
    },
    commitConfig(state, configData) {
      state.apiConfig = configData;
    },
    commitState(state, stateData) {
      state.apiState = stateData;
    }
  },

@@ -81,6 +85,28 @@ export default new Vuex.Store({
      })
    },

    updateState(context, uri=`${context.getters.uri}/state`) {
      axios.get(uri)
      .then(response => { 
        context.commit('commitError', '');
        context.commit('commitState', response.data);
      })
      .catch(error => {
        var errormsg = '';
        if (error.response) {
          errormsg = `${error.response.status}: ${error.response.data}`
          console.log(errormsg)
        } else if (error.request) {
          errormsg = `${error.message}`
          console.log(errormsg)
        } else {
          errormsg = `${error.message}`
          console.log(errormsg)
        }
        context.dispatch('errorState', errormsg);
      })
    },

    resetState(context) {
      context.commit('changeWaiting', false);
      context.commit('changeConnected', false);