From 6b2efbf12a277aa94e471a8866e786df9fbe9aff Mon Sep 17 00:00:00 2001 From: An Phan Date: Fri, 11 Mar 2016 18:49:54 +0800 Subject: [PATCH] Move nprogress logic to main.js --- resources/assets/js/main.js | 3 +++ resources/assets/js/services/http.js | 9 +-------- resources/assets/js/services/playback.js | 1 + resources/assets/js/stores/playlist.js | 6 ------ resources/assets/js/stores/user.js | 10 ---------- 5 files changed, 5 insertions(+), 24 deletions(-) diff --git a/resources/assets/js/main.js b/resources/assets/js/main.js index 7a48e5b4..c220e2dc 100644 --- a/resources/assets/js/main.js +++ b/resources/assets/js/main.js @@ -1,5 +1,6 @@ import Vue from 'vue'; import ls from './services/ls'; +import NProgress from 'nprogress'; var app = new Vue(require('./app.vue')); @@ -18,6 +19,8 @@ Vue.http.interceptors.push({ }, response(r) { + NProgress.done(); + if (r.status === 400 || r.status === 401) { if (r.request.method !== 'POST' && r.request.url !== 'me') { // This is not a failed login. Log out then. diff --git a/resources/assets/js/services/http.js b/resources/assets/js/services/http.js index 557505c6..6ce879c1 100644 --- a/resources/assets/js/services/http.js +++ b/resources/assets/js/services/http.js @@ -1,18 +1,11 @@ import Vue from 'vue'; -import NProgress from 'nprogress'; /** * Responsible for all HTTP requests. */ export default { request(method, url, data, successCb = null, errorCb = null) { - return Vue.http[method](url, data).then(successCb).catch(() => { - NProgress.done(); - - if (errorCb) { - errorCb(); - } - }); + return Vue.http[method](url, data).then(successCb, errorCb); }, get(url, successCb = null, errorCb = null) { diff --git a/resources/assets/js/services/playback.js b/resources/assets/js/services/playback.js index 5d8e4874..0dfc66bc 100644 --- a/resources/assets/js/services/playback.js +++ b/resources/assets/js/services/playback.js @@ -7,6 +7,7 @@ import artistStore from '../stores/artist'; import albumStore from '../stores/album'; import preferenceStore from '../stores/preference'; import ls from '../services/ls'; +import http from '../services/http'; import config from '../config'; export default { diff --git a/resources/assets/js/stores/playlist.js b/resources/assets/js/stores/playlist.js index 8267d97e..e8d7d8ab 100644 --- a/resources/assets/js/stores/playlist.js +++ b/resources/assets/js/stores/playlist.js @@ -52,8 +52,6 @@ export default { NProgress.start(); http.post('playlist', { name, songs }, response => { - NProgress.done(); - var playlist = response.data; playlist.songs = songs; this.getSongs(playlist); @@ -75,8 +73,6 @@ export default { NProgress.start(); http.delete(`playlist/${playlist.id}`, {}, () => { - NProgress.done(); - this.state.playlists = _.without(this.state.playlists, playlist); if (cb) { @@ -134,8 +130,6 @@ export default { NProgress.start(); http.put(`playlist/${playlist.id}`, { name: playlist.name }, () => { - NProgress.done(); - if (cb) { cb(); } diff --git a/resources/assets/js/stores/user.js b/resources/assets/js/stores/user.js index a0a4171f..6d169e30 100644 --- a/resources/assets/js/stores/user.js +++ b/resources/assets/js/stores/user.js @@ -91,8 +91,6 @@ export default { login(email, password, successCb = null, errorCb = null) { NProgress.start(); http.post('me', { email, password }, () => { - NProgress.done(); - if (successCb) { successCb(); } @@ -127,8 +125,6 @@ export default { name: this.current().name, email: this.current().email }, () => { - NProgress.done(); - this.setAvatar(); if (cb) { @@ -150,8 +146,6 @@ export default { NProgress.start(); http.post('user', { name, email, password }, response => { - NProgress.done(); - var user = response.data; this.setAvatar(user); @@ -176,8 +170,6 @@ export default { NProgress.start(); http.put(`user/${user.id}`, { name, email, password }, () => { - NProgress.done(); - this.setAvatar(user); user.password = ''; @@ -197,8 +189,6 @@ export default { NProgress.start(); http.delete(`user/${user.id}`, {}, () => { - NProgress.done(); - this.state.users = _.without(this.state.users, user); // Mama, just killed a man