diff --git a/quasar.conf.js b/quasar.conf.js index 65dde83..1fbb0be 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -89,7 +89,12 @@ module.exports = configure(function(ctx) { iconSet: 'material-icons', // Quasar icon set lang: 'de', // Quasar language pack config: { - dark: 'auto' + dark: 'auto', + loadingBar: { + position: 'top', + color: 'warning', + size: '5px' + } }, // Possible values for "importStrategy": @@ -105,7 +110,13 @@ module.exports = configure(function(ctx) { // directives: [], // Quasar plugins - plugins: ['LocalStorage', 'SessionStorage', 'Loading', 'Notify'] + plugins: [ + 'LocalStorage', + 'SessionStorage', + 'Loading', + 'Notify', + 'LoadingBar' + ] }, // animations: 'all', // --- includes all animations diff --git a/src/components/loading.ts b/src/components/loading.ts new file mode 100644 index 0000000..cb90de3 --- /dev/null +++ b/src/components/loading.ts @@ -0,0 +1,11 @@ +import { watch, WatchSource } from '@vue/composition-api'; +import { LoadingBar } from 'quasar'; + +function setLoadingBar(loading: WatchSource) { + return watch(loading, loading => { + if (loading) LoadingBar.start(10000); + if (!loading) LoadingBar.stop(); + }); +} + +export default setLoadingBar; diff --git a/src/plugins/balance/pages/MainPage.vue b/src/plugins/balance/pages/MainPage.vue index 7dec833..0ddcd33 100644 --- a/src/plugins/balance/pages/MainPage.vue +++ b/src/plugins/balance/pages/MainPage.vue @@ -27,13 +27,24 @@ import { computed, defineComponent } from '@vue/composition-api'; import EssentialLink from 'src/components/navigation/EssentialLink.vue'; import mainRoutes from 'src/plugins/balance/routes'; +import { Store } from 'vuex'; +import { BalanceInterface } from 'src/plugins/balance/store/balance'; +import setLoadingBar from 'components/loading'; +import { StateInterface } from 'src/store'; export default defineComponent({ // name: 'PageName' components: { EssentialLink }, setup(_, { root }) { + const store = >root.$store; + const loading = computed(() => { + return (store.state.balance).loading > 0; + }); const checkMain = computed(() => { return root.$route.matched.length == 2; }); + + setLoadingBar(loading); + return { checkMain, mainRoutes }; } }); diff --git a/src/plugins/balance/store/balance.ts b/src/plugins/balance/store/balance.ts index 79ec232..f86939f 100644 --- a/src/plugins/balance/store/balance.ts +++ b/src/plugins/balance/store/balance.ts @@ -11,13 +11,15 @@ interface BalanceResponse { export interface BalanceInterface extends BalanceResponse { limit: number; + loading: number; } const state: BalanceInterface = { balance: 0, credit: 0, debit: 0, - limit: 0 + limit: 0, + loading: 0 }; const mutations: MutationTree = { @@ -32,11 +34,16 @@ const mutations: MutationTree = { }, setLimit(state, data: number) { state.limit = data; + }, + setLoading(state, data = true) { + if (data) state.loading += 1; + else state.loading -= 1; } }; const actions: ActionTree = { getBalance({ commit, rootState }) { + commit('setLoading'); axios /* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */ .get(`/users/${rootState.user.currentUser?.userid}/balance`) @@ -47,9 +54,11 @@ const actions: ActionTree = { }) .catch(err => { console.warn(err); - }); + }) + .finally(() => commit('setLoading', false)); }, - getLimit({ rootState }) { + getLimit({ rootState, commit }) { + commit('setLoading'); axios /* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */ .get(`/users/${rootState.user.currentUser?.userid}/balance/limit`) @@ -58,9 +67,11 @@ const actions: ActionTree = { }) .catch(err => { console.warn(err); - }); + }) + .finally(() => commit('setLoading', false)); }, - changeBalance({ rootState, dispatch }, amount: number) { + changeBalance({ rootState, dispatch, commit }, amount: number) { + commit('setLoading'); axios /* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */ .put(`/users/${rootState.user.currentUser?.userid}/balance`, < @@ -71,7 +82,8 @@ const actions: ActionTree = { .then(() => { dispatch('getBalance').catch(err => console.warn(err)); }) - .catch(err => console.warn(err)); + .catch(err => console.warn(err)) + .finally(() => commit('setLoading', false)); } }; diff --git a/src/plugins/user/components/settings/MainUserSettings.vue b/src/plugins/user/components/settings/MainUserSettings.vue index c2f3376..e1e4064 100644 --- a/src/plugins/user/components/settings/MainUserSettings.vue +++ b/src/plugins/user/components/settings/MainUserSettings.vue @@ -1,6 +1,5 @@