Improve "no bot available" errorhandling

This commit is contained in:
Matthias 2021-08-29 10:08:58 +02:00
parent 29d908bf47
commit acd702dab3
3 changed files with 10 additions and 10 deletions

View File

@ -30,7 +30,7 @@
<b-navbar-nav class="ml-auto"> <b-navbar-nav class="ml-auto">
<li class="nav-item text-secondary mr-2"> <li class="nav-item text-secondary mr-2">
<b-nav-text class="verticalCenter small mr-2"> <b-nav-text class="verticalCenter small mr-2">
{{ botName }} {{ botName || 'No bot selected' }}
</b-nav-text> </b-nav-text>
<b-nav-text class="verticalCenter"> <b-nav-text class="verticalCenter">
{{ isBotOnline ? 'Online' : 'Offline' }} {{ isBotOnline ? 'Online' : 'Offline' }}

View File

@ -2,8 +2,7 @@ import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router'; import VueRouter, { RouteConfig } from 'vue-router';
import Home from '@/views/Home.vue'; import Home from '@/views/Home.vue';
import Error404 from '@/views/Error404.vue'; import Error404 from '@/views/Error404.vue';
import store from '@/store';
import userService from '@/shared/userService';
Vue.use(VueRouter); Vue.use(VueRouter);
@ -68,11 +67,8 @@ const router = new VueRouter({
}); });
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
if (to.name === 'Login' && userService.loggedIn()) { const hasBots = store.getters['ftbot/hasBots'];
// No login if already logged in if (!to.meta?.allowAnonymous && !hasBots) {
next({ path: '/' });
}
if (!to.meta?.allowAnonymous && !userService.loggedIn()) {
// Forward to login if login is required // Forward to login if login is required
next({ next({
path: '/login', path: '/login',

View File

@ -71,8 +71,12 @@ export default function createBotStore(store) {
}; };
// Autocreate Actions // Autocreate Actions
Object.keys(BotStoreActions).forEach((e) => { Object.keys(BotStoreActions).forEach((e) => {
actions[e] = ({ state, dispatch }, ...args) => { actions[e] = ({ state, dispatch, getters }, ...args) => {
return dispatch(`${state.selectedBot}/${e}`, ...args); if (getters.hasBots) {
return dispatch(`${state.selectedBot}/${e}`, ...args);
}
console.warn(`bot ${state.selectedBot} is not registered.`);
return {};
}; };
}); });