From 69c688e4ea228f0a54834242bedad1053b5904fc Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 24 Apr 2023 18:10:13 +1200 Subject: [PATCH 1/4] Very basic Loader component for use on Accounts.vue (still needs styling etc.) --- resources/js/app.js | 13 +++- resources/js/components/Loader.vue | 77 ++++++++++++++++++++++++ resources/js/components/OtpDisplayer.vue | 17 ++++-- resources/js/views/Accounts.vue | 61 ++++++++++--------- 4 files changed, 132 insertions(+), 36 deletions(-) create mode 100644 resources/js/components/Loader.vue diff --git a/resources/js/app.js b/resources/js/app.js index a36fd937..9b20aae5 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -20,7 +20,8 @@ const app = new Vue({ userPreferences: window.userPreferences, isDemoApp: window.isDemoApp, isTestingApp: window.isTestingApp, - prefersDarkScheme: window.matchMedia('(prefers-color-scheme: dark)').matches + prefersDarkScheme: window.matchMedia('(prefers-color-scheme: dark)').matches, + loaderActive: false }, computed: { @@ -44,8 +45,16 @@ const app = new Vue({ methods: { setDarkScheme ({ matches }) { this.prefersDarkScheme = matches + }, + + showLoader() { + this.loaderActive = true + }, + + hideLoader() { + this.loaderActive = false } }, i18n, router, -}); \ No newline at end of file +}); diff --git a/resources/js/components/Loader.vue b/resources/js/components/Loader.vue new file mode 100644 index 00000000..359a3969 --- /dev/null +++ b/resources/js/components/Loader.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/resources/js/components/OtpDisplayer.vue b/resources/js/components/OtpDisplayer.vue index 2e3118d3..abcc328e 100644 --- a/resources/js/components/OtpDisplayer.vue +++ b/resources/js/components/OtpDisplayer.vue @@ -144,7 +144,7 @@ this.internal_account = data.account this.internal_icon = data.icon this.internal_otp_type = data.otp_type - + if( this.isHMacBased(data.otp_type) && data.counter ) { this.internal_counter = data.counter } @@ -165,13 +165,18 @@ await this.getHOTP() } else this.$router.push({ name: 'genericError', params: { err: this.$t('errors.not_a_supported_otp_type') } }); - + this.$parent.isActive = true this.focusOnOTP() } catch(error) { this.clearOTP() } + finally { + this.$root.hideLoader(); + } + } else { + this.$root.hideLoader(); } }, @@ -232,7 +237,7 @@ }, startTotpLoop: async function() { - + let otp = await this.getOtp() this.internal_password = otp.password @@ -258,7 +263,7 @@ // ● ● ● ● ●|● ◌ ◌ ◌ ◌ | // | | || | // | | |<-------->|--remainingTimeBeforeEndOfPeriod (for remainingTimeout) - // durationBetweenTwoDots-->|-|< || + // durationBetweenTwoDots-->|-|< || // (for dotToDotInterval) | | >||<---durationFromFirstToNextDot (for firstDotToNextOneTimeout) // | // | @@ -276,7 +281,7 @@ // We determine the position of the closest dot next to the generated_at timestamp let relativePosition = (elapsedTimeInCurrentPeriod * 10) / period let dotIndex = (Math.floor(relativePosition) +1) - + // We switch the dot on this.lastActiveDot = dots.querySelector('li:nth-child(' + dotIndex + ')'); this.lastActiveDot.setAttribute('data-is-active', true); @@ -365,4 +370,4 @@ this.stopLoop() } } - \ No newline at end of file + diff --git a/resources/js/views/Accounts.vue b/resources/js/views/Accounts.vue index 08abb9f2..7a5a2f9c 100644 --- a/resources/js/views/Accounts.vue +++ b/resources/js/views/Accounts.vue @@ -1,5 +1,7 @@