Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

Commit 242ee08

Browse files
authored
Merge pull request #158 from ProgrammingLab/kp/loading
NOW LOADING
2 parents 7a4e506 + f4c1ef9 commit 242ee08

File tree

5 files changed

+95
-8
lines changed

5 files changed

+95
-8
lines changed

src/App.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<template>
22
<div id="app">
33
<error-page v-if="isError"/>
4+
<loading-indicator class="loading"/>
45
<router-view v-show="!isError"/>
56
</div>
67
</template>
78

89
<script>
910
import { mapGetters } from 'vuex';
1011
import ErrorPage from './components/ErrorPage.vue';
12+
import LoadingIndicator from './components/LoadingIndicator.vue';
1113
1214
export default {
1315
components: {
1416
ErrorPage,
17+
LoadingIndicator,
1518
},
1619
computed: {
1720
...mapGetters('criticalError', ['isError']),
@@ -24,13 +27,22 @@ export default {
2427
</script>
2528

2629
<style>
27-
html { height: 100%; }
28-
body {
29-
font-family: 'Noto Sans JP', sans-serif;
30-
height: 100%;
31-
}
30+
html {
31+
height: 100%;
32+
}
3233
33-
#app {
34-
height: 100%;
35-
}
34+
body {
35+
font-family: 'Noto Sans JP', sans-serif;
36+
height: 100%;
37+
}
38+
39+
#app {
40+
height: 100%;
41+
}
42+
43+
.loading {
44+
position: fixed;
45+
top: 0;
46+
z-index: 127;
47+
}
3648
</style>

src/components/LoadingIndicator.vue

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template>
2+
<div class="loading-indicator-container">
3+
<div :class="[ isLoading ? 'loading-indicator-active' : 'loading-indicator-inactive' ]"></div>
4+
</div>
5+
</template>
6+
7+
<script>
8+
import { mapState } from 'vuex';
9+
10+
export default {
11+
computed: {
12+
...mapState('ui', ['isLoading']),
13+
},
14+
};
15+
</script>
16+
17+
<style scoped>
18+
.loading-indicator-container {
19+
height: 5px;
20+
width: 100%;
21+
}
22+
23+
.loading-indicator-inactive {
24+
height: 100%;
25+
width: 0;
26+
margin-left: 0;
27+
}
28+
29+
.loading-indicator-active {
30+
height: 100%;
31+
background-color: cornflowerblue;
32+
animation: loading 1.5s linear infinite;
33+
}
34+
35+
@keyframes loading {
36+
0% {
37+
width: 0;
38+
margin-left: 0;
39+
}
40+
41+
50% {
42+
margin-left: 0;
43+
width: 50%;
44+
}
45+
46+
100% {
47+
margin-left: 100%;
48+
width: 0%;
49+
}
50+
}
51+
</style>

src/router.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const router = new Router({
9696
});
9797

9898
router.beforeEach(async (to, from, next) => {
99+
store.commit('ui/setLoading');
99100
store.commit('criticalError/clearError');
100101
if (to.matched.length === 0) {
101102
store.dispatch('criticalError/createError', {
@@ -134,4 +135,9 @@ router.beforeEach(async (to, from, next) => {
134135
next();
135136
});
136137

138+
// eslint-disable-next-line no-unused-vars
139+
router.afterEach(async (to, from) => {
140+
store.commit('ui/clearLoading');
141+
});
142+
137143
export default router;

src/store/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import emailConfirmations from './modules/emailConfirmations';
1111
import memberIntroduction from './modules/memberIntroduction';
1212
import editUser from './modules/editUser';
1313
import invitation from './modules/invitation';
14+
import ui from './modules/ui';
1415

1516
Vue.use(Vuex);
1617

@@ -27,6 +28,7 @@ export default new Vuex.Store({
2728
memberIntroduction,
2829
editUser,
2930
invitation,
31+
ui,
3032
},
3133
plugins: [
3234
createPersistedState({

src/store/modules/ui/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
namespaced: true,
3+
state: {
4+
isLoading: false,
5+
},
6+
/* eslint-disable no-param-reassign */
7+
mutations: {
8+
setLoading(state) {
9+
state.isLoading = true;
10+
},
11+
clearLoading(state) {
12+
state.isLoading = false;
13+
},
14+
},
15+
/* eslint-enable no-param-reassign */
16+
};

0 commit comments

Comments
 (0)