import { DialogProgrammatic as Dialog } from 'buefy' import router from '@/router/index' const state = { signalServerConnected: false, loginSuccess: false, error: null, serverStatus: {} } const getters = { displayError: state => state.error, displayUserList: state => state.userList, displayLoginStatus: state => state.loginSuccess, displayServerStatus: state => state.signalServerConnected } const actions = { signalConnected ({ commit }) { commit('SIGNAL_SUCCESS') }, signalError ({ commit }, error) { commit('SIGNAL_ERROR', error) }, login ({ commit }, success) { if (success) commit('LOGIN_SUCCESS') else commit('LOGIN_ERROR') }, serverStatus ({ commit }, serverStatus) { commit('SET_SERVERSTATUS', serverStatus) }, createRoom ({ commit, dispatch }, code) { commit('CREATE_ROOM') dispatch('room/setRoomCode', code, { root: true }) }, error ({ commit }, error) { commit('ERROR', error) } } const mutations = { SIGNAL_SUCCESS (state) { state.signalServerConnected = true }, SIGNAL_ERROR (state, error) { state.signalServerConnected = false state.error = error }, LOGIN_SUCCESS (state) { state.loginSuccess = true }, LOGIN_ERROR (state) { state.loginSuccess = false }, SET_SERVERSTATUS (state, serverStatus) { state.serverStatus = serverStatus }, CREATE_ROOM (state) { state.room = true state.admin = true router.push({ name: 'Room' }) }, ERROR (state, error) { state.error = error Dialog.alert(error) } } export default { namespaced: true, state, getters, actions, mutations }