blob: d972b869a0f4eacdcd9185aa8ddb8769b4b744bb [file] [log] [blame]
Yoshie Muranaka3be801a2020-04-21 11:34:56 -07001<template>
2 <transition name="fade">
3 <b-progress
4 v-if="!isLoadingComplete"
5 :value="loadingIndicatorValue"
6 height="0.4rem"
7 />
8 </transition>
9</template>
10
11<script>
12export default {
13 data() {
14 return {
15 loadingIndicatorValue: 0,
16 isLoadingComplete: false,
17 loadingIntervalId: null,
18 timeoutId: null
19 };
20 },
21 created() {
22 this.$root.$on('loader::start', () => {
23 this.startLoadingInterval();
24 });
25 this.$root.$on('loader::end', () => {
26 this.endLoadingInterval();
27 });
28 this.$root.$on('loader::hide', () => {
29 this.hideLoadingBar();
30 });
31 },
32 methods: {
33 startLoadingInterval() {
34 this.clearLoadingInterval();
35 this.clearTimeout();
36 this.loadingIndicatorValue = 0;
37 this.isLoadingComplete = false;
38 this.loadingIntervalId = setInterval(() => {
39 this.loadingIndicatorValue += 1;
40 if (this.loadingIndicatorValue > 100) this.clearLoadingInterval();
41 }, 100);
42 },
43 endLoadingInterval() {
44 this.clearLoadingInterval();
45 this.clearTimeout();
46 this.loadingIndicatorValue = 100;
47 this.timeoutId = setTimeout(() => {
48 // Let animation complete before hiding
49 // the loading bar
50 this.isLoadingComplete = true;
51 }, 1000);
52 },
53 hideLoadingBar() {
54 this.clearLoadingInterval();
55 this.clearTimeout();
56 this.loadingIndicatorValue = 0;
57 this.isLoadingComplete = true;
58 },
59 clearLoadingInterval() {
60 if (this.loadingIntervalId) clearInterval(this.loadingIntervalId);
61 this.loadingIntervalId = null;
62 },
63 clearTimeout() {
64 if (this.timeoutId) clearTimeout(this.timeoutId);
65 this.timeoutId = null;
66 }
67 }
68};
69</script>
70
71<style lang="scss" scoped>
Yoshie Muranakaa9ac43b2020-05-05 08:37:07 -070072@import 'src/assets/styles/helpers';
73
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070074.progress {
75 position: absolute;
76 left: 0;
77 right: 0;
78 bottom: -0.4rem;
79 opacity: 1;
80 transition: opacity $duration--moderate-01 $standard-easing--productive;
81
82 &.fade-enter,
83 &.fade-leave-to {
84 opacity: 0;
85 }
86}
87</style>