Move nprogress logic to main.js

This commit is contained in:
An Phan 2016-03-11 18:49:54 +08:00
parent d1e9e48776
commit 6b2efbf12a
5 changed files with 5 additions and 24 deletions

View file

@ -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.

View file

@ -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) {

View file

@ -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 {

View file

@ -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();
}

View file

@ -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