diff --git a/src/app/Utils.php b/src/app/Utils.php --- a/src/app/Utils.php +++ b/src/app/Utils.php @@ -382,10 +382,7 @@ $env['view'] = 'root'; $env['jsapp'] = 'user.js'; - if ($path == 'meet' || strpos($path, 'meet/') === 0) { - $env['view'] = 'meet'; - $env['jsapp'] = 'meet.js'; - } elseif ($req_domain == "admin.$sys_domain") { + if ($req_domain == "admin.$sys_domain") { $env['jsapp'] = 'admin.js'; } diff --git a/src/resources/js/app.js b/src/resources/js/app.js --- a/src/resources/js/app.js +++ b/src/resources/js/app.js @@ -13,6 +13,61 @@ const loader = '
Loading
' +let isLoading = 0 + +// Lock the UI with the 'loading...' element +const startLoading = () => { + isLoading++ + let loading = $('#app > .app-loader').removeClass('fadeOut') + if (!loading.length) { + $('#app').append($(loader)) + } +} + +// Hide "loading" overlay +const stopLoading = () => { + if (isLoading > 0) { + $('#app > .app-loader').addClass('fadeOut') + isLoading--; + } +} + +let loadingRoute + +// Note: This has to be before the app is created +// Note: You cannot use app inside of the function +window.router.beforeEach((to, from, next) => { + // check if the route requires authentication and user is not logged in + if (to.matched.some(route => route.meta.requiresAuth) && !store.state.isLoggedIn) { + // remember the original request, to use after login + store.state.afterLogin = to; + + // redirect to login page + next({ name: 'login' }) + + return + } + + if (to.meta.loading) { + startLoading() + loadingRoute = to.name + } + + next() +}) + +window.router.afterEach((to, from) => { + if (to.name && loadingRoute === to.name) { + stopLoading() + loadingRoute = null + } + + // When changing a page remove old: + // - error page + // - modal backdrop + $('#error-page,.modal-backdrop.show').remove() +}) + const app = new Vue({ el: '#app', components: { @@ -23,7 +78,6 @@ router: window.router, data() { return { - isLoading: true, isAdmin: window.isAdmin } }, @@ -102,11 +156,7 @@ delete axios.defaults.headers.common.Authorization if (redirect !== false) { - if (this.hasRoute('login')) { - this.$router.push({ name: 'login' }) - } else { - location.href = window.config['app.url'] + '/login' - } + this.$router.push({ name: 'login' }) } clearTimeout(this.refreshTimeout) @@ -119,18 +169,10 @@ removeLoader(elem) { $(elem).find('.app-loader').remove() }, - startLoading() { - this.isLoading = true - // Lock the UI with the 'loading...' element - let loading = $('#app > .app-loader').removeClass('fadeOut') - if (!loading.length) { - $('#app').append($(loader)) - } - }, - // Hide "loading" overlay - stopLoading() { - $('#app > .app-loader').addClass('fadeOut') - this.isLoading = false + startLoading, + stopLoading, + isLoading() { + return isLoading > 0 }, errorPage(code, msg) { // Until https://github.com/vuejs/vue-router/issues/977 is implemented @@ -164,9 +206,10 @@ // Remember requested route to come back to it after log in if (this.$route.meta.requiresAuth) { store.state.afterLogin = this.$route + this.logoutUser() + } else { + this.logoutUser(false) } - - this.logoutUser() } else { this.errorPage(error.response.status, error.response.statusText) } @@ -417,13 +460,3 @@ return Promise.reject(error) } ) - -// TODO: Investigate if we can use App component's childMounted() method instead -window.router.afterEach((to, from) => { - // When changing a page remove old: - // - error page - // - modal backdrop - $('#error-page,.modal-backdrop.show').remove() - - app.updateBodyClass() -}) diff --git a/src/resources/js/bootstrap.js b/src/resources/js/bootstrap.js --- a/src/resources/js/bootstrap.js +++ b/src/resources/js/bootstrap.js @@ -68,21 +68,6 @@ } }) -router.beforeEach((to, from, next) => { - // check if the route requires authentication and user is not logged in - if (to.matched.some(route => route.meta.requiresAuth) && !store.state.isLoggedIn) { - // remember the original request, to use after login - store.state.afterLogin = to; - - // redirect to login page - next({ name: 'login' }) - - return - } - - next() -}) - /** * We'll load the axios HTTP library which allows us to easily issue requests * to our Laravel back-end. This library automatically handles sending the diff --git a/src/resources/js/meet.js b/src/resources/js/meet.js deleted file mode 100644 --- a/src/resources/js/meet.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Application code for the Meet UI - */ - -import routes from './routes-meet.js' - -window.routes = routes -window.isAdmin = false - -require('./app') - -// Register additional icons -import { library } from '@fortawesome/fontawesome-svg-core' - -import { - faAlignLeft, - faCompress, - faDesktop, - faExpand, - faMicrophone, - faPowerOff, - faUser, - faShieldAlt, - faVideo, - faVolumeMute -} from '@fortawesome/free-solid-svg-icons' - -// Register only these icons we need -library.add( - faAlignLeft, - faCompress, - faDesktop, - faExpand, - faMicrophone, - faPowerOff, - faUser, - faShieldAlt, - faVideo, - faVolumeMute -) diff --git a/src/resources/js/routes-meet.js b/src/resources/js/routes-meet.js deleted file mode 100644 --- a/src/resources/js/routes-meet.js +++ /dev/null @@ -1,23 +0,0 @@ -import PageComponent from '../vue/Page' -import LogoutComponent from '../vue/Logout' -import RoomComponent from '../vue/Meet/Room' - -const routes = [ - { - component: LogoutComponent, - name: 'logout', - path: '/logout' - }, - { - component: RoomComponent, - name: 'room', - path: '/meet/:room' - }, - { - component: PageComponent, - name: '404', - path: '*' - } -] - -export default routes diff --git a/src/resources/js/routes-user.js b/src/resources/js/routes-user.js --- a/src/resources/js/routes-user.js +++ b/src/resources/js/routes-user.js @@ -13,6 +13,11 @@ import UserProfileDeleteComponent from '../vue/User/ProfileDelete' import WalletComponent from '../vue/Wallet' +// Here's a list of lazy-loaded components +// Note: you can pack multiple components into the same chunk, webpackChunkName +// is also used to get a sensible file name instead of numbers +const RoomComponent = () => import(/* webpackChunkName: "room" */ '../vue/Meet/Room.vue') + const routes = [ { path: '/dashboard', @@ -60,6 +65,12 @@ meta: { requiresAuth: true } }, { + component: RoomComponent, + name: 'room', + path: '/meet/:room', + meta: { loading: true } + }, + { path: '/rooms', name: 'rooms', component: MeetComponent, diff --git a/src/resources/views/meet.blade.php b/src/resources/views/meet.blade.php deleted file mode 100644 --- a/src/resources/views/meet.blade.php +++ /dev/null @@ -1,10 +0,0 @@ -@extends('layouts.app') -@section('title', "Meet") -@section('content') -
- - -
- -
-@endsection diff --git a/src/resources/vue/Admin/Dashboard.vue b/src/resources/vue/Admin/Dashboard.vue --- a/src/resources/vue/Admin/Dashboard.vue +++ b/src/resources/vue/Admin/Dashboard.vue @@ -1,5 +1,5 @@