Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show loader during an action #16

Merged
merged 3 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"vue": "^2.6.10",
"vue-codemirror": "^4.0.6",
"vue-fragment": "^1.5.1",
"vue-loading-overlay": "^3.2.0",
"vue-router": "^3.0.3",
"vuetify": "^2.0.0",
"vuex": "^3.0.1",
Expand Down
28 changes: 23 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
<template>
<Layout>
<v-container>
<router-view></router-view>
</v-container>
</Layout>
<fragment>
<loading
:active.sync="isLoading"
color="indigo"
loader="dots"
is-full-page
></loading>
<Layout>
<v-container>
<router-view></router-view>
</v-container>
</Layout>
</fragment>
</template>

<script>
import Loading from 'vue-loading-overlay';
import 'vue-loading-overlay/dist/vue-loading.css';
import { mapGetters } from 'vuex';

import Layout from './components/layout';

export default {
name: 'App',
components: {
Layout,
Loading,
},
data: () => ({
//
}),
computed: {
...mapGetters([
'isLoading',
]),
},
};
</script>
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'roboto-fontface/css/roboto/roboto-fontface.css';
import '@mdi/font/css/materialdesignicons.css';
import { sync } from 'vuex-router-sync';
import { Plugin } from 'vue-fragment';
import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store';
import vuetify from './plugins/vuetify';
import 'roboto-fontface/css/roboto/roboto-fontface.css';
import '@mdi/font/css/materialdesignicons.css';

Vue.config.productionTip = false;
sync(store, router);
Expand Down
12 changes: 10 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Vue from 'vue';
import Vuex from 'vuex';

import authentication from './modules/authentication';
import { Loading } from './plugins';

Vue.use(Vuex);

Expand All @@ -12,24 +13,31 @@ const debug = process.env.NODE_ENV !== 'production';
const plugins = debug ? [
createLogger(),
// createPersistedState(),
Loading,
] : [
createPersistedState(),
Loading,
];

export default new Vuex.Store({
state: {
baseUrl: '/api',
loading: false,
},
mutations: {

setLoading(state, loading) {
state.loading = loading;
},
},
actions: {

},
modules: {
authentication,
},
getters: {
isLoading(state) {
return state.loading;
},
getErrorMessage: () => (response) => {
console.log('HERE', response);
const { status, data: { data: { errors } = {}, message } } = response;
Expand Down
1 change: 1 addition & 0 deletions src/store/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Loading } from './loading';
12 changes: 12 additions & 0 deletions src/store/plugins/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default (store) => {
store.subscribeAction({
before: (action) => {
console.log(`before action ${action.type}`);
store.commit('setLoading', true, { root: true });
},
after: (action) => {
console.log(`after action ${action.type}`);
store.commit('setLoading', false, { root: true });
},
});
};
4 changes: 1 addition & 3 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module.exports = {
devServer: {
proxy: {
'/api': {
target: 'https://localhost:8000',
ws: true,
changeOrigin: true,
target: 'http://localhost:8000',
headers: {
Connection: 'keep-alive',
},
Expand Down