diff options
author | dartcafe <github@dartcafe.de> | 2021-02-27 13:10:48 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2021-02-27 13:10:48 +0300 |
commit | 985fa6e5ebc878b00c64cd371079e45a491d2b58 (patch) | |
tree | a9a56b8afb4c56e316fddea30073f7e0ed280c7a /src/js/components/Base | |
parent | 7a05a361da2b5e0879e9e83dcb2f6d9fa3009671 (diff) |
use async/await
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/components/Base')
-rw-r--r-- | src/js/components/Base/ParticipantsList.vue | 19 | ||||
-rw-r--r-- | src/js/components/Base/PersonalLink.vue | 31 | ||||
-rw-r--r-- | src/js/components/Base/PublicRegisterModal.vue | 67 | ||||
-rw-r--r-- | src/js/components/Base/UserSearch.vue | 25 |
4 files changed, 66 insertions, 76 deletions
diff --git a/src/js/components/Base/ParticipantsList.vue b/src/js/components/Base/ParticipantsList.vue index e8542d17..a2017df0 100644 --- a/src/js/components/Base/ParticipantsList.vue +++ b/src/js/components/Base/ParticipantsList.vue @@ -65,17 +65,14 @@ export default { }, methods: { - getAddresses() { - this.$store.dispatch('poll/getParticipantsEmailAddresses', { pollId: this.poll.id }) - .then((response) => { - this.$copyText(response.data) - .then(() => { - showSuccess(t('polls', 'Link copied to clipboard')) - }) - }) - .catch(() => { - showError(t('polls', 'Error while copying link to clipboard')) - }) + async getAddresses() { + try { + const response = await this.$store.dispatch('poll/getParticipantsEmailAddresses', { pollId: this.poll.id }) + await this.$copyText(response.data) + showSuccess(t('polls', 'Link copied to clipboard')) + } catch (e) { + showError(t('polls', 'Error while copying link to clipboard')) + } }, }, } diff --git a/src/js/components/Base/PersonalLink.vue b/src/js/components/Base/PersonalLink.vue index 9816d307..6b509840 100644 --- a/src/js/components/Base/PersonalLink.vue +++ b/src/js/components/Base/PersonalLink.vue @@ -63,25 +63,22 @@ export default { }, methods: { - resendInvitation() { - this.$store.dispatch('share/resendInvitation') - .then((response) => { - showSuccess(t('polls', 'Invitation resent to {emailAddress}', { emailAddress: response.data.share.emailAddress })) - }) - .catch(() => { - showError(t('polls', 'Mail could not be resent to {emailAddress}', { emailAddress: this.share.emailAddress })) - }) + async resendInvitation() { + try { + const response = await this.$store.dispatch('share/resendInvitation') + showSuccess(t('polls', 'Invitation resent to {emailAddress}', { emailAddress: response.data.share.emailAddress })) + } catch (e) { + showError(t('polls', 'Mail could not be resent to {emailAddress}', { emailAddress: this.share.emailAddress })) + } }, - copyLink() { - this.$copyText(this.personalLink).then( - function() { - showSuccess(t('polls', 'Link copied to clipboard')) - }, - function() { - showError(t('polls', 'Error while copying link to clipboard')) - } - ) + async copyLink() { + try { + await this.$copyText(this.personalLink) + showSuccess(t('polls', 'Link copied to clipboard')) + } catch (e) { + showError(t('polls', 'Error while copying link to clipboard')) + } }, }, } diff --git a/src/js/components/Base/PublicRegisterModal.vue b/src/js/components/Base/PublicRegisterModal.vue index 7b50e3f1..4c76490b 100644 --- a/src/js/components/Base/PublicRegisterModal.vue +++ b/src/js/components/Base/PublicRegisterModal.vue @@ -220,56 +220,53 @@ export default { window.location.assign(window.location.protocol + '//' + window.location.host + this.loginLink) }, - validatePublicUsername: debounce(function() { + validatePublicUsername: debounce(async function() { if (this.userName.length > 2) { - return axios.post(generateUrl('apps/polls/check/username'), { userName: this.userName, token: this.$route.params.token }) - .then(() => { - this.checkingUserName = false - this.isValidName = true - }) - .catch(() => { - this.checkingUserName = false - this.isValidName = false - }) + try { + await axios.post(generateUrl('apps/polls/check/username'), { userName: this.userName, token: this.$route.params.token }) + this.checkingUserName = false + this.isValidName = true + } catch (e) { + this.checkingUserName = false + this.isValidName = false + } } else { this.checkingUserName = false this.isValidName = false } }, 500), - validateEmailAddress: debounce(function() { + validateEmailAddress: debounce(async function() { if (this.emailAddress.length > 0) { - return axios.get(generateUrl('apps/polls/check/emailaddress') + '/' + this.emailAddress) - .then(() => { - this.isValidEmailAddress = true - this.checkingEmailAddress = false - }) - .catch(() => { - this.isValidEmailAddress = false - this.checkingEmailAddress = false - }) + try { + await axios.get(generateUrl('apps/polls/check/emailaddress') + '/' + this.emailAddress) + this.isValidEmailAddress = true + this.checkingEmailAddress = false + } catch (e) { + this.isValidEmailAddress = false + this.checkingEmailAddress = false + } } else { this.isValidEmailAddress = false this.checkingEmailAddress = false } }, 500), - submitRegistration() { + async submitRegistration() { if (this.isValidName && (this.isValidEmailAddress || this.emailAddress.length === 0)) { - this.$store.dispatch('share/register', { userName: this.userName, emailAddress: this.emailAddress }) - .then((response) => { - if (this.$route.params.token === response.token) { - this.$store.dispatch({ type: 'poll/get', pollId: this.$route.params.id, token: this.$route.params.token }) - this.closeModal() - } else { - this.redirecting = true - this.$router.replace({ name: 'publicVote', params: { token: response.token } }) - this.closeModal() - } - }) - .catch(() => { - showError(t('polls', 'Error saving username', 1, this.poll.title)) - }) + try { + const response = await this.$store.dispatch('share/register', { userName: this.userName, emailAddress: this.emailAddress }) + if (this.$route.params.token === response.token) { + this.$store.dispatch({ type: 'poll/get', pollId: this.$route.params.id, token: this.$route.params.token }) + this.closeModal() + } else { + this.redirecting = true + this.$router.replace({ name: 'publicVote', params: { token: response.token } }) + this.closeModal() + } + } catch (e) { + showError(t('polls', 'Error saving username', 1, this.poll.title)) + } } }, }, diff --git a/src/js/components/Base/UserSearch.vue b/src/js/components/Base/UserSearch.vue index b637773e..c660cccb 100644 --- a/src/js/components/Base/UserSearch.vue +++ b/src/js/components/Base/UserSearch.vue @@ -73,7 +73,7 @@ export default { }, methods: { - loadUsersAsync: debounce(function(query) { + loadUsersAsync: debounce(async function(query) { if (!query) { this.users = [] return @@ -83,19 +83,18 @@ export default { this.searchToken.cancel() } this.searchToken = axios.CancelToken.source() - axios.get(generateUrl('apps/polls/search/users/' + query), { cancelToken: this.searchToken.token }) - .then((response) => { - this.users = response.data.siteusers + try { + const response = await axios.get(generateUrl('apps/polls/search/users/' + query), { cancelToken: this.searchToken.token }) + this.users = response.data.siteusers + this.isLoading = false + } catch (e) { + if (axios.isCancel(e)) { + // request was cancelled + } else { + console.error(e.response) this.isLoading = false - }) - .catch((error) => { - if (axios.isCancel(error)) { - // request was cancelled - } else { - console.error(error.response) - this.isLoading = false - } - }) + } + } }, 250), addShare(payload) { |