diff options
author | dartcafe <github@dartcafe.de> | 2021-02-21 01:21:37 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2021-02-21 01:21:37 +0300 |
commit | 59e96f17d92c24716563d0954481e2b4f110c46e (patch) | |
tree | 45f681841166727d919f35f79e733af286775794 /src/js/views | |
parent | d3281a5b834efdf7e9597197813809867617c224 (diff) |
frontend
Diffstat (limited to 'src/js/views')
-rw-r--r-- | src/js/views/Vote.vue | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/src/js/views/Vote.vue b/src/js/views/Vote.vue index 14dba799..afaf400a 100644 --- a/src/js/views/Vote.vue +++ b/src/js/views/Vote.vue @@ -21,7 +21,7 @@ --> <template> - <AppContent :class="{ closed: closed }"> + <AppContent :class="[{ closed: closed }, poll.type]"> <div class="header-actions"> <Actions> <ActionButton :icon="sortIcon" @click="ranked = !ranked"> @@ -95,6 +95,7 @@ <script> import axios from '@nextcloud/axios' +import { showError } from '@nextcloud/dialogs' import { generateUrl } from '@nextcloud/router' import linkifyUrls from 'linkify-urls' import { mapState, mapGetters } from 'vuex' @@ -305,35 +306,6 @@ export default { }, methods: { - async watchPoll() { - this.cancelToken = axios.CancelToken.source() - let watching = true - let lastUpdated = 0 - while (watching) { - await axios.get(generateUrl('apps/polls/watch/' + this.$route.params.id + '?offset=' + lastUpdated), { cancelToken: this.cancelToken.token }) - .then((response) => { - console.debug('update detected', response.data.updates) - response.data.updates.forEach((item) => { - lastUpdated = (item.updated > lastUpdated) ? item.updated : lastUpdated - if (item.table === 'polls') { - this.$store.dispatch('poll/get') - } else { - this.$store.dispatch('poll/' + item.table + '/list') - } - }) - }) - .catch((error) => { - if (axios.isCancel(error)) { - watching = false - } else if (error?.response) { - if (error.response.status !== 304) { - console.error(error.response) - } - } - }) - } - }, - openOptions() { emit('toggle-sidebar', { open: true, activeTab: 'options' }) }, @@ -366,13 +338,43 @@ export default { } } }, + async watchPoll() { + this.cancelToken = axios.CancelToken.source() + let watching = true + let lastUpdated = 0 + try { + while (watching) { + const response = await axios.get(generateUrl('apps/polls/watch/' + this.$route.params.id + '?offset=' + lastUpdated), { cancelToken: this.cancelToken.token }) + console.debug('update detected', response.data.updates) + response.data.updates.forEach((item) => { + lastUpdated = (item.updated > lastUpdated) ? item.updated : lastUpdated + if (item.table === 'polls') { + this.$store.dispatch('poll/get') + } else { + this.$store.dispatch('poll/' + item.table + '/list') + } + }) + watching = true + } + } catch (error) { + watching = false + + if (!axios.isCancel(error)) { + if (error.response.status !== 304) { + showError(t('polls', 'Error retrieving updates from server, reload page')) + console.error(error.response) + } + } + } + }, }, } + </script> <style lang="scss" scoped> .description { - white-space: pre; + white-space: pre-wrap; } .header-actions { |