Add logic to add/remove a substore

This commit is contained in:
Matthias 2021-08-28 20:23:20 +02:00
parent a253377124
commit cb8d0af126
2 changed files with 20 additions and 5 deletions

View File

@ -16,7 +16,7 @@
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import { Action, State } from 'vuex-class';
import { Action, Getter, State } from 'vuex-class';
import RefreshIcon from 'vue-material-design-icons/Refresh.vue';
@Component({ components: { RefreshIcon } })
@ -40,7 +40,7 @@ export default class ReloadControl extends Vue {
this.stopRefresh();
}
@State loggedIn;
@Getter loggedIn;
@State autoRefresh!: boolean;

View File

@ -31,8 +31,15 @@ export default function createBotStore(store) {
});
const mutations = {
addBot(state: FTMultiBotState, botName: string) {
state.availableBots = [...state.availableBots, botName];
addBot(state: FTMultiBotState, botId: string) {
state.availableBots = [...state.availableBots, botId];
},
removeBot(state: FTMultiBotState, botId: string) {
const index = state.availableBots.indexOf(botId);
if (index > -1) {
state.availableBots.splice(index, 1);
state.availableBots = [...state.availableBots];
}
},
};
@ -44,9 +51,17 @@ export default function createBotStore(store) {
// TODO: handle error!
}
console.log('add bot', botId);
store.registerModule(`ftbot/${botId}`, createBotSubStore(botId));
store.registerModule(['ftbot', botId], createBotSubStore(botId));
commit('addBot', botId);
},
removeBot({ commit, getters }, botId: string) {
if (getters.allAvailableBots.includes(botId)) {
store.unregisterModule(`ftbot/${botId}`);
commit('removeBot', botId);
} else {
console.warn(`bot ${botId} not found! could not remove`);
}
},
};
// Autocreate Actions
Object.keys(BotStoreActions).forEach((e) => {