Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2021-02-27 22:30:47 +0300
committerdartcafe <github@dartcafe.de>2021-02-27 22:30:47 +0300
commit9a7b8f7b4e41e1dd40d6e7e01939afeac00c25d8 (patch)
tree075829b0880ff899ff317cb0f0fee26a27fed4cd /src/js/views/Vote.vue
parentf27e13152e4898ec3b47e58eb9980acb755350be (diff)
move watchPoll to mixin
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/views/Vote.vue')
-rw-r--r--src/js/views/Vote.vue77
1 files changed, 4 insertions, 73 deletions
diff --git a/src/js/views/Vote.vue b/src/js/views/Vote.vue
index 336afbfe..0871dde5 100644
--- a/src/js/views/Vote.vue
+++ b/src/js/views/Vote.vue
@@ -95,8 +95,6 @@
</template>
<script>
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import linkifyUrls from 'linkify-urls'
import { mapState, mapGetters } from 'vuex'
@@ -113,6 +111,7 @@ import PublicRegisterModal from '../components/Base/PublicRegisterModal'
import PublicEmail from '../components/Base/PublicEmail'
import Subscription from '../components/Subscription/Subscription'
import VoteTable from '../components/VoteTable/VoteTable'
+import { watchPolls } from '../mixins/watchPolls'
export default {
name: 'Vote',
@@ -132,6 +131,8 @@ export default {
VoteTable,
},
+ mixins: [watchPolls],
+
data() {
return {
cancelToken: null,
@@ -302,7 +303,7 @@ export default {
} else {
emit('toggle-sidebar', { open: (window.innerWidth > 920) })
}
- this.watchPoll()
+ this.watchPolls()
},
beforeDestroy() {
@@ -353,76 +354,6 @@ export default {
showError(t('polls', 'Error saving email address {emailAddress}', { emailAddress: emailAddress }))
}
},
-
- async watchPoll() {
- console.debug('polls', 'Watch for updates')
-
- this.cancelToken = axios.CancelToken.source()
- let endPoint = 'apps/polls'
-
- if (this.$route.name === 'publicVote') {
- endPoint = endPoint + '/s/' + this.$route.params.token
- } else if (this.$route.name === 'vote') {
- endPoint = endPoint + '/poll/' + this.$route.params.id
- } else {
- this.watching = false
- }
-
- while (this.watching) {
- try {
- const response = await axios.get(generateUrl(endPoint + '/watch'), {
- params: { offset: this.lastUpdated },
- cancelToken: this.cancelToken.token,
- })
- const dispatches = []
-
- console.debug('polls', 'update detected', response.data.updates)
-
- response.data.updates.forEach((item) => {
- this.lastUpdated = (item.updated > this.lastUpdated) ? item.updated : this.lastUpdated
- if (item.table === 'polls') {
- dispatches.push('poll/get')
- } else {
- dispatches.push(item.table + '/list')
- }
- })
- const requests = dispatches.map(dispatches => this.$store.dispatch(dispatches))
- await Promise.all(requests)
-
- this.watching = true
-
- } catch (error) {
- this.watching = false
-
- if (axios.isCancel(error)) {
- console.debug('Watch canceld')
- } else if (error.response) {
-
- if (error.response.status === 304) {
-
- this.watching = true
-
- } else if (error.response.status === 503) {
-
- console.debug('Server not available, reconnect watch in 30 sec')
-
- await new Promise(resolve => setTimeout(resolve, 30000))
- this.watching = true
-
- } else {
-
- console.error('Unhandled error watching polls', error)
-
- }
- } else if (error.request) {
-
- console.debug('Watch aborted')
- this.watching = true
-
- }
- }
- }
- },
},
}