From 2bf13fdb1e63d078dd380a07f403d25fd4fa62df Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 19 Nov 2018 20:48:34 +0000 Subject: [PATCH] --- app/ayanova/src/main.js | 81 ++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/app/ayanova/src/main.js b/app/ayanova/src/main.js index 19d13705..f2c1b92e 100644 --- a/app/ayanova/src/main.js +++ b/app/ayanova/src/main.js @@ -12,27 +12,74 @@ Vue.config.productionTip = false; Vue.config.errorHandler = errorHandler.handleVueError; window.onerror = errorHandler.handleGeneralError; -//Loading indicator +//Loading indicator on route change, probably don't need this +//but do need one for ajax calls -router.beforeResolve((to, from, next) => { - // If this isn't an initial page load. - from; - if (to.name) { - // Start the route progress bar. - //NProgress.start() - // eslint-disable-next-line - console.log("---===LOADING===---"); - } - next(); +// router.beforeResolve((to, from, next) => { +// // If this isn't an initial page load. +// from; +// if (to.name) { +// // Start the route progress bar. +// //NProgress.start() +// // eslint-disable-next-line +// console.log("---===LOADING===---"); +// } +// next(); +// }); + +// router.afterEach((to, from) => { +// // Complete the animation of the route progress bar. +// //NProgress.done() +// to; +// from; +// // eslint-disable-next-line +// console.log("---===FINISHED LOADING===---"); +// }); + +// Store a copy of the fetch function +var _oldFetch = fetch; + +// Create our new version of the fetch function +window.fetch = function() { + // Create hooks + var fetchStart = new Event("fetchStart", { + view: document, + bubbles: true, + cancelable: false + }); + var fetchEnd = new Event("fetchEnd", { + view: document, + bubbles: true, + cancelable: false + }); + + // Pass the supplied arguments to the real fetch function + var fetchCall = _oldFetch.apply(this, arguments); + + // Trigger the fetchStart event + document.dispatchEvent(fetchStart); + + fetchCall + .then(function() { + // Trigger the fetchEnd event + document.dispatchEvent(fetchEnd); + }) + .catch(function() { + // Trigger the fetchEnd event + document.dispatchEvent(fetchEnd); + }); + + return fetchCall; +}; + +document.addEventListener("fetchStart", function() { + // eslint-disable-next-line + console.log("Show spinner"); }); -router.afterEach((to, from) => { - // Complete the animation of the route progress bar. - //NProgress.done() - to; - from; +document.addEventListener("fetchEnd", function() { // eslint-disable-next-line - console.log("---===FINISHED LOADING===---"); + console.log("Hide spinner"); }); new Vue({