diff --git a/src/store/index.ts b/src/store/index.ts index e527304a..68fbc3e7 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -146,4 +146,5 @@ store.registerModule('ftbot', createBotStore(store)); UserService.getAvailableBotList().forEach((e) => { store.dispatch('ftbot/addBot', e); }); +store.dispatch('ftbot/selectFirstBot'); export default store; diff --git a/src/store/modules/botStoreWrapper.ts b/src/store/modules/botStoreWrapper.ts index b83cc109..8b2831c9 100644 --- a/src/store/modules/botStoreWrapper.ts +++ b/src/store/modules/botStoreWrapper.ts @@ -14,7 +14,7 @@ export enum MultiBotStoreGetters { export default function createBotStore(store) { const state: FTMultiBotState = { - selectedBot: 'ftbot.0', + selectedBot: '', availableBots: [], }; @@ -46,7 +46,7 @@ export default function createBotStore(store) { const mutations = { selectBot(state: FTMultiBotState, botId: string) { - if (botId in state.availableBots) { + if (state.availableBots.includes(botId)) { state.selectedBot = botId; } else { console.warn(`Botid ${botId} not available, but selected`); @@ -84,6 +84,11 @@ export default function createBotStore(store) { console.warn(`bot ${botId} not found! could not remove`); } }, + selectFirstBot({ commit, getters }) { + if (getters.hasBots) { + commit('selectBot', getters.allAvailableBots[0]); + } + }, }; // Autocreate Actions Object.keys(BotStoreActions).forEach((e) => {