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) => {
store.dispatch('ftbot/addBot', e);
});
store.dispatch('ftbot/selectFirstBot');
export default store;

View File

@ -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) => {