Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 1 | <template> |
| 2 | <transition name="fade"> |
Dixsie Wolmers | 61c65ef | 2020-10-06 14:43:49 -0500 | [diff] [blame] | 3 | <b-progress v-if="!isLoadingComplete"> |
Derick Montague | de87f67 | 2020-06-27 11:59:17 -0500 | [diff] [blame] | 4 | <b-progress-bar |
Dixsie Wolmers | 3559304 | 2020-07-17 09:38:12 -0500 | [diff] [blame] | 5 | striped |
| 6 | animated |
Derick Montague | de87f67 | 2020-06-27 11:59:17 -0500 | [diff] [blame] | 7 | :value="loadingIndicatorValue" |
| 8 | :aria-label="$t('global.ariaLabel.progressBar')" |
| 9 | /> |
| 10 | </b-progress> |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 11 | </transition> |
| 12 | </template> |
| 13 | |
| 14 | <script> |
| 15 | export default { |
| 16 | data() { |
| 17 | return { |
| 18 | loadingIndicatorValue: 0, |
| 19 | isLoadingComplete: false, |
| 20 | loadingIntervalId: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 21 | timeoutId: null, |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 22 | }; |
| 23 | }, |
| 24 | created() { |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame^] | 25 | this.$root.$on('loader-start', () => { |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 26 | this.startLoadingInterval(); |
| 27 | }); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame^] | 28 | this.$root.$on('loader-end', () => { |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 29 | this.endLoadingInterval(); |
| 30 | }); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame^] | 31 | this.$root.$on('loader-hide', () => { |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 32 | this.hideLoadingBar(); |
| 33 | }); |
| 34 | }, |
| 35 | methods: { |
| 36 | startLoadingInterval() { |
| 37 | this.clearLoadingInterval(); |
| 38 | this.clearTimeout(); |
| 39 | this.loadingIndicatorValue = 0; |
| 40 | this.isLoadingComplete = false; |
| 41 | this.loadingIntervalId = setInterval(() => { |
| 42 | this.loadingIndicatorValue += 1; |
| 43 | if (this.loadingIndicatorValue > 100) this.clearLoadingInterval(); |
| 44 | }, 100); |
| 45 | }, |
| 46 | endLoadingInterval() { |
| 47 | this.clearLoadingInterval(); |
| 48 | this.clearTimeout(); |
| 49 | this.loadingIndicatorValue = 100; |
| 50 | this.timeoutId = setTimeout(() => { |
| 51 | // Let animation complete before hiding |
| 52 | // the loading bar |
| 53 | this.isLoadingComplete = true; |
| 54 | }, 1000); |
| 55 | }, |
| 56 | hideLoadingBar() { |
| 57 | this.clearLoadingInterval(); |
| 58 | this.clearTimeout(); |
| 59 | this.loadingIndicatorValue = 0; |
| 60 | this.isLoadingComplete = true; |
| 61 | }, |
| 62 | clearLoadingInterval() { |
| 63 | if (this.loadingIntervalId) clearInterval(this.loadingIntervalId); |
| 64 | this.loadingIntervalId = null; |
| 65 | }, |
| 66 | clearTimeout() { |
| 67 | if (this.timeoutId) clearTimeout(this.timeoutId); |
| 68 | this.timeoutId = null; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 69 | }, |
| 70 | }, |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 71 | }; |
| 72 | </script> |
| 73 | |
| 74 | <style lang="scss" scoped> |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 75 | .progress { |
| 76 | position: absolute; |
| 77 | left: 0; |
| 78 | right: 0; |
| 79 | bottom: -0.4rem; |
| 80 | opacity: 1; |
| 81 | transition: opacity $duration--moderate-01 $standard-easing--productive; |
Dixsie Wolmers | 61c65ef | 2020-10-06 14:43:49 -0500 | [diff] [blame] | 82 | height: 0.4rem; |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 83 | &.fade-enter, |
| 84 | &.fade-leave-to { |
| 85 | opacity: 0; |
| 86 | } |
| 87 | } |
Mateusz Gapski | 21d6de0 | 2020-07-29 14:28:23 +0200 | [diff] [blame] | 88 | .progress-bar { |
| 89 | background-color: $loading-color; |
| 90 | } |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 91 | </style> |