From 10d13d788e88d9c3612d04de73968d777acc2b14 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 31 Aug 2021 20:30:19 +0200 Subject: [PATCH] Fix setIsBotOnline --- src/shared/apiService.ts | 4 ++-- src/store/index.ts | 7 ------- src/store/modules/ftbot/index.ts | 6 +++++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/shared/apiService.ts b/src/shared/apiService.ts index 241e6f5a..6a0797de 100644 --- a/src/shared/apiService.ts +++ b/src/shared/apiService.ts @@ -6,7 +6,7 @@ import { UserService } from './userService'; */ let globalStore; -export function useApi(userService: UserService) { +export function useApi(userService: UserService, botId: string) { const api = axios.create({ baseURL: userService.getBaseUrl(), timeout: 10000, @@ -60,7 +60,7 @@ export function useApi(userService: UserService) { } if ((err.response && err.response.status === 500) || err.message === 'Network Error') { console.log('Bot not running...'); - globalStore.dispatch('setIsBotOnline', false); + globalStore.dispatch(`ftbot/${botId}/setIsBotOnline`, false); } return new Promise((resolve, reject) => { diff --git a/src/store/index.ts b/src/store/index.ts index 922eb2eb..e3bb27ff 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -57,13 +57,6 @@ const store = new Vuex.Store({ setLoggedIn({ commit }, loggedin: boolean) { commit('setLoggedIn', loggedin); }, - setIsBotOnline({ commit, dispatch }, isOnline) { - commit('setIsBotOnline', isOnline); - if (isOnline === false) { - console.log('disabling autorun'); - dispatch('ftbot/setAutoRefresh', false); - } - }, async loadUIVersion({ commit }) { if (process.env.NODE_ENV !== 'development') { try { diff --git a/src/store/modules/ftbot/index.ts b/src/store/modules/ftbot/index.ts index b0d5c59a..2b8efe66 100644 --- a/src/store/modules/ftbot/index.ts +++ b/src/store/modules/ftbot/index.ts @@ -133,7 +133,8 @@ export enum BotStoreActions { export function createBotSubStore(botId: string) { const userService = useUserService(botId); - const { api } = useApi(userService); + const { api } = useApi(userService, botId); + return { namespaced: true, @@ -410,6 +411,9 @@ export function createBotSubStore(botId: string) { [BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) { commit('updateRefreshRequired', refreshRequired); }, + [BotStoreActions.setIsBotOnline]({ commit }, refreshRequired: boolean) { + commit('setIsBotOnline', refreshRequired); + }, [BotStoreActions.refreshOnce]({ dispatch }) { dispatch('getVersion'); },