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">
<li class="nav-item text-secondary mr-2">
<b-nav-text class="verticalCenter small mr-2">
{{ botName }}
{{ botName || 'No bot selected' }}
</b-nav-text>
<b-nav-text class="verticalCenter">
{{ isBotOnline ? 'Online' : 'Offline' }}

View File

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

View File

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