diff --git a/src/store/index.ts b/src/store/index.ts index 9aad6184..d1eb7bd4 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -15,9 +15,8 @@ const AUTO_REFRESH = 'ft_auto_refresh'; Vue.use(Vuex); const initCurrentTheme = getCurrentTheme(); -export default new Vuex.Store({ +const store = new Vuex.Store({ modules: { - ftbot: createBotStore(), alerts: alertsModule, layout: layoutModule, uiSettings: settingsModule, @@ -152,3 +151,7 @@ export default new Vuex.Store({ }, }, }); + +store.registerModule('ftbot', createBotStore(store)); +store.dispatch('ftbot/addBot', 'ftbot.0'); +export default store; diff --git a/src/store/modules/botStoreWrapper.ts b/src/store/modules/botStoreWrapper.ts index d9894d08..c010a485 100644 --- a/src/store/modules/botStoreWrapper.ts +++ b/src/store/modules/botStoreWrapper.ts @@ -5,18 +5,21 @@ interface FTMultiBotState { availableBots: string[]; } -export default function createBotStore() { +export default function createBotStore(store) { const state: FTMultiBotState = { selectedBot: 'ftbot.0', - availableBots: ['ftbot.0'], + availableBots: [], }; // All getters working on all bots should be prefixed with all. const getters = { - selectedBot(state: FTMultiBotState) { + hasBots(state: FTMultiBotState): boolean { + return state.availableBots.length > 0; + }, + selectedBot(state: FTMultiBotState): string { return state.selectedBot; }, - allAvailableBots(state: FTMultiBotState) { + allAvailableBots(state: FTMultiBotState): string[] { return state.availableBots; }, }; @@ -35,12 +38,14 @@ export default function createBotStore() { const actions = { // Actions automatically filled below - addBot({ getters, commit }, botName: string) { - if (getters.allAvailableBots.includes(botName)) { + addBot({ getters, commit }, botId: string) { + if (getters.allAvailableBots.includes(botId)) { // throw 'Bot already present'; // TODO: handle error! } - commit('addBot', botName); + console.log('add bot', botId); + store.registerModule(`ftbot/${botId}`, createBotSubStore(botId)); + commit('addBot', botId); }, }; // Autocreate Actions @@ -52,9 +57,9 @@ export default function createBotStore() { return { namespaced: true, - modules: { - 'ftbot.0': createBotSubStore('ftbot.0'), - }, + // modules: { + // 'ftbot.0': createBotSubStore('ftbot.0'), + // }, state, mutations,