Autoselect first available Bot

This commit is contained in:
Matthias 2021-08-29 10:57:49 +02:00
parent 9ad4fefffa
commit 79c6618b2b
2 changed files with 8 additions and 2 deletions

View File

@ -146,4 +146,5 @@ store.registerModule('ftbot', createBotStore(store));
UserService.getAvailableBotList().forEach((e) => { UserService.getAvailableBotList().forEach((e) => {
store.dispatch('ftbot/addBot', e); store.dispatch('ftbot/addBot', e);
}); });
store.dispatch('ftbot/selectFirstBot');
export default store; export default store;

View File

@ -14,7 +14,7 @@ export enum MultiBotStoreGetters {
export default function createBotStore(store) { export default function createBotStore(store) {
const state: FTMultiBotState = { const state: FTMultiBotState = {
selectedBot: 'ftbot.0', selectedBot: '',
availableBots: [], availableBots: [],
}; };
@ -46,7 +46,7 @@ export default function createBotStore(store) {
const mutations = { const mutations = {
selectBot(state: FTMultiBotState, botId: string) { selectBot(state: FTMultiBotState, botId: string) {
if (botId in state.availableBots) { if (state.availableBots.includes(botId)) {
state.selectedBot = botId; state.selectedBot = botId;
} else { } else {
console.warn(`Botid ${botId} not available, but selected`); 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`); console.warn(`bot ${botId} not found! could not remove`);
} }
}, },
selectFirstBot({ commit, getters }) {
if (getters.hasBots) {
commit('selectBot', getters.allAvailableBots[0]);
}
},
}; };
// Autocreate Actions // Autocreate Actions
Object.keys(BotStoreActions).forEach((e) => { Object.keys(BotStoreActions).forEach((e) => {