From 0eed2ccca8a0980c161bb5a52b211c507e0ffef5 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 18 Jun 2019 20:28:31 +0000 Subject: Feature/polls attempt 2 --- src/components/status/status.js | 12 ++++++++---- src/components/status/status.vue | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src/components/status') diff --git a/src/components/status/status.js b/src/components/status/status.js index ea4c2b9d..d2452935 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -1,6 +1,7 @@ import Attachment from '../attachment/attachment.vue' import FavoriteButton from '../favorite_button/favorite_button.vue' import RetweetButton from '../retweet_button/retweet_button.vue' +import Poll from '../poll/poll.vue' import ExtraButtons from '../extra_buttons/extra_buttons.vue' import PostStatusForm from '../post_status_form/post_status_form.vue' import UserCard from '../user_card/user_card.vue' @@ -8,6 +9,7 @@ import UserAvatar from '../user_avatar/user_avatar.vue' import Gallery from '../gallery/gallery.vue' import LinkPreview from '../link-preview/link-preview.vue' import AvatarList from '../avatar_list/avatar_list.vue' +import Timeago from '../timeago/timeago.vue' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import fileType from 'src/services/file_type/file_type.service' import { highlightClass, highlightStyle } from '../../services/user_highlighter/user_highlighter.js' @@ -216,8 +218,8 @@ const Status = { if (!this.status.summary) return '' const decodedSummary = unescape(this.status.summary) const behavior = typeof this.$store.state.config.subjectLineBehavior === 'undefined' - ? this.$store.state.instance.subjectLineBehavior - : this.$store.state.config.subjectLineBehavior + ? this.$store.state.instance.subjectLineBehavior + : this.$store.state.config.subjectLineBehavior const startsWithRe = decodedSummary.match(/^re[: ]/i) if (behavior !== 'noop' && startsWithRe || behavior === 'masto') { return decodedSummary @@ -285,11 +287,13 @@ const Status = { RetweetButton, ExtraButtons, PostStatusForm, + Poll, UserCard, UserAvatar, Gallery, LinkPreview, - AvatarList + AvatarList, + Timeago }, methods: { visibilityIcon (visibility) { @@ -377,7 +381,7 @@ const Status = { this.preview = find(statuses, { 'id': targetId }) // or if we have to fetch it if (!this.preview) { - this.$store.state.api.backendInteractor.fetchStatus({id}).then((status) => { + this.$store.state.api.backendInteractor.fetchStatus({ id }).then((status) => { this.preview = status }) } diff --git a/src/components/status/status.vue b/src/components/status/status.vue index e1dd81ac..58402f7e 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -52,7 +52,7 @@ - +
@@ -123,6 +123,10 @@ {{$t("general.show_less")}}
+
+ +
+
Date: Thu, 20 Jun 2019 13:02:04 +0000 Subject: Move poll state handling to its own module --- src/components/poll/poll.js | 35 ++++++++++--------- src/components/poll/poll.vue | 4 +-- src/components/status/status.vue | 2 +- src/main.js | 4 ++- src/modules/polls.js | 73 ++++++++++++++++++++++++++++++++++++++++ src/modules/statuses.js | 12 ------- 6 files changed, 96 insertions(+), 34 deletions(-) create mode 100644 src/modules/polls.js (limited to 'src/components/status') diff --git a/src/components/poll/poll.js b/src/components/poll/poll.js index ecacbc35..9988070e 100644 --- a/src/components/poll/poll.js +++ b/src/components/poll/poll.js @@ -3,26 +3,33 @@ import { forEach, map } from 'lodash' export default { name: 'Poll', - props: ['poll', 'statusId'], + props: ['pollId'], components: { Timeago }, data () { return { loading: false, - choices: [], - refreshInterval: null + choices: [] } }, - created () { - this.refreshInterval = setTimeout(this.refreshPoll, 30 * 1000) - // Initialize choices to booleans and set its length to match options - this.choices = this.poll.options.map(_ => false) + mounted () { + this.$store.dispatch('trackPoll', this.pollId) }, destroyed () { - clearTimeout(this.refreshInterval) + this.$store.dispatch('untrackPoll', this.pollId) }, computed: { + poll () { + const storePoll = this.$store.state.polls.pollsObject[this.pollId] + return storePoll || {} + }, + options () { + return (this.poll && this.poll.options) || [] + }, + expiresAt () { + return (this.poll && this.poll.expires_at) || 0 + }, expired () { - return Date.now() > Date.parse(this.poll.expires_at) + return Date.now() > Date.parse(this.expiresAt) }, loggedIn () { return this.$store.state.users.currentUser @@ -33,9 +40,6 @@ export default { totalVotesCount () { return this.poll.votes_count }, - expiresAt () { - return Date.parse(this.poll.expires_at).toLocaleString() - }, containerClass () { return { loading: this.loading @@ -55,11 +59,6 @@ export default { } }, methods: { - refreshPoll () { - if (this.expired) return - this.fetchPoll() - this.refreshInterval = setTimeout(this.refreshPoll, 30 * 1000) - }, percentageForOption (count) { return this.totalVotesCount === 0 ? 0 : Math.round(count / this.totalVotesCount * 100) }, @@ -104,4 +103,4 @@ export default { }) } } -} \ No newline at end of file +} diff --git a/src/components/poll/poll.vue b/src/components/poll/poll.vue index 4c765ae2..bb67101a 100644 --- a/src/components/poll/poll.vue +++ b/src/components/poll/poll.vue @@ -2,7 +2,7 @@
@@ -50,7 +50,7 @@ {{totalVotesCount}} {{ $t("polls.votes") }} ยท 
- +
diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 58402f7e..821a7a83 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -124,7 +124,7 @@
- +
diff --git a/src/main.js b/src/main.js index d0f2674b..3287fa2b 100644 --- a/src/main.js +++ b/src/main.js @@ -14,6 +14,7 @@ import authFlowModule from './modules/auth_flow.js' import mediaViewerModule from './modules/media_viewer.js' import oauthTokensModule from './modules/oauth_tokens.js' import reportsModule from './modules/reports.js' +import pollsModule from './modules/polls.js' import VueI18n from 'vue-i18n' @@ -72,7 +73,8 @@ const persistedStateOptions = { authFlow: authFlowModule, mediaViewer: mediaViewerModule, oauthTokens: oauthTokensModule, - reports: reportsModule + reports: reportsModule, + polls: pollsModule }, plugins: [persistedState, pushNotifications], strict: false // Socket modifies itself, let's ignore this for now. diff --git a/src/modules/polls.js b/src/modules/polls.js new file mode 100644 index 00000000..0f0964aa --- /dev/null +++ b/src/modules/polls.js @@ -0,0 +1,73 @@ +import { each, merge } from 'lodash' +import { set } from 'vue' + +const polls = { + state: { + // Contains key = id, value = number of trackers for this poll + trackedPolls: {}, + pollsObject: {} + }, + mutations: { + addNewStatuses (state, { statuses }) { + each(statuses, status => { + if (status.poll) { + set(state.pollsObject, status.poll.id, status.poll) + } + }) + }, + mergePoll (state, poll) { + state.pollsObject[poll.id] = merge(state.pollsObject[poll.id], poll) + }, + trackPoll (state, pollId) { + const currentValue = state.trackedPolls[pollId] + if (currentValue) { + set(state.trackedPolls, pollId, currentValue + 1) + } else { + set(state.trackedPolls, pollId, 1) + } + }, + untrackPoll (state, pollId) { + const currentValue = state.trackedPolls[pollId] + if (currentValue) { + set(state.trackedPolls, pollId, currentValue - 1) + } else { + set(state.trackedPolls, pollId, 0) + } + } + }, + actions: { + updatePoll ({ rootState, commit }, pollId) { + return rootState.api.backendInteractor.fetchPoll(pollId).then(poll => { + commit('mergePoll', poll) + return poll + }) + }, + updateTrackedPoll ({ rootState, dispatch, commit }, pollId) { + rootState.api.backendInteractor.fetchPoll(pollId).then(poll => { + setTimeout(() => { + if (rootState.polls.trackedPolls[pollId]) { + dispatch('updateTrackedPoll', pollId) + } + }, 30 * 1000) + commit('mergePoll', poll) + }) + }, + trackPoll ({ rootState, commit, dispatch }, pollId) { + if (!rootState.polls.trackedPolls[pollId]) { + setTimeout(() => dispatch('updateTrackedPoll', pollId), 30 * 1000) + } + commit('trackPoll', pollId) + }, + untrackPoll ({ commit }, pollId) { + commit('untrackPoll', pollId) + }, + votePoll ({ rootState, commit }, { id, pollId, choices }) { + return rootState.api.backendInteractor.vote(pollId, choices).then(poll => { + commit('mergePoll', poll) + return poll + }) + } + } +} + +export default polls diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 5f09b8f5..235098d3 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -582,18 +582,6 @@ const statuses = { ]).then(([favoritedByUsers, rebloggedByUsers]) => commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers }) ) - }, - votePoll ({ rootState, commit }, { id, pollId, choices }) { - return rootState.api.backendInteractor.vote(pollId, choices).then(poll => { - commit('updateStatusWithPoll', { id, poll }) - return poll - }) - }, - refreshPoll ({ rootState, commit }, { id, pollId }) { - return rootState.api.backendInteractor.fetchPoll(pollId).then(poll => { - commit('updateStatusWithPoll', { id, poll }) - return poll - }) } }, mutations -- cgit v1.2.3-70-g09d2 From 947f69a9531a7d99e79df3fc05f5e795de717dc6 Mon Sep 17 00:00:00 2001 From: Shpuld Shpludson Date: Sat, 22 Jun 2019 14:01:36 +0000 Subject: Fix: problems with polls state --- src/components/poll/poll.js | 12 +++++++++--- src/components/status/status.vue | 2 +- src/modules/polls.js | 31 ++++++++++++++----------------- 3 files changed, 24 insertions(+), 21 deletions(-) (limited to 'src/components/status') diff --git a/src/components/poll/poll.js b/src/components/poll/poll.js index 9988070e..98db5582 100644 --- a/src/components/poll/poll.js +++ b/src/components/poll/poll.js @@ -3,7 +3,7 @@ import { forEach, map } from 'lodash' export default { name: 'Poll', - props: ['pollId'], + props: ['basePoll'], components: { Timeago }, data () { return { @@ -11,13 +11,19 @@ export default { choices: [] } }, - mounted () { + created () { + if (!this.$store.state.polls.pollsObject[this.pollId]) { + this.$store.dispatch('mergeOrAddPoll', this.basePoll) + } this.$store.dispatch('trackPoll', this.pollId) }, destroyed () { this.$store.dispatch('untrackPoll', this.pollId) }, computed: { + pollId () { + return this.basePoll.id + }, poll () { const storePoll = this.$store.state.polls.pollsObject[this.pollId] return storePoll || {} @@ -29,7 +35,7 @@ export default { return (this.poll && this.poll.expires_at) || 0 }, expired () { - return Date.now() > Date.parse(this.expiresAt) + return (this.poll && this.poll.expired) || false }, loggedIn () { return this.$store.state.users.currentUser diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 821a7a83..440e1957 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -124,7 +124,7 @@
- +
diff --git a/src/modules/polls.js b/src/modules/polls.js index 0f0964aa..e6158b63 100644 --- a/src/modules/polls.js +++ b/src/modules/polls.js @@ -1,4 +1,4 @@ -import { each, merge } from 'lodash' +import { merge } from 'lodash' import { set } from 'vue' const polls = { @@ -8,15 +8,15 @@ const polls = { pollsObject: {} }, mutations: { - addNewStatuses (state, { statuses }) { - each(statuses, status => { - if (status.poll) { - set(state.pollsObject, status.poll.id, status.poll) - } - }) - }, - mergePoll (state, poll) { - state.pollsObject[poll.id] = merge(state.pollsObject[poll.id], poll) + mergeOrAddPoll (state, poll) { + const existingPoll = state.pollsObject[poll.id] + // Make expired-state change trigger re-renders properly + poll.expired = Date.now() > Date.parse(poll.expires_at) + if (existingPoll) { + set(state.pollsObject, poll.id, merge(existingPoll, poll)) + } else { + set(state.pollsObject, poll.id, poll) + } }, trackPoll (state, pollId) { const currentValue = state.trackedPolls[pollId] @@ -36,11 +36,8 @@ const polls = { } }, actions: { - updatePoll ({ rootState, commit }, pollId) { - return rootState.api.backendInteractor.fetchPoll(pollId).then(poll => { - commit('mergePoll', poll) - return poll - }) + mergeOrAddPoll ({ commit }, poll) { + commit('mergeOrAddPoll', poll) }, updateTrackedPoll ({ rootState, dispatch, commit }, pollId) { rootState.api.backendInteractor.fetchPoll(pollId).then(poll => { @@ -49,7 +46,7 @@ const polls = { dispatch('updateTrackedPoll', pollId) } }, 30 * 1000) - commit('mergePoll', poll) + commit('mergeOrAddPoll', poll) }) }, trackPoll ({ rootState, commit, dispatch }, pollId) { @@ -63,7 +60,7 @@ const polls = { }, votePoll ({ rootState, commit }, { id, pollId, choices }) { return rootState.api.backendInteractor.vote(pollId, choices).then(poll => { - commit('mergePoll', poll) + commit('mergeOrAddPoll', poll) return poll }) } -- cgit v1.2.3-70-g09d2 From 8d6750d9c2816e33a0444cd978f94009d8b85d47 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 5 Jul 2019 10:17:44 +0300 Subject: eslint --fix --ext .js,.vue src --- src/App.vue | 108 ++- src/components/about/about.vue | 6 +- src/components/attachment/attachment.vue | 100 ++- src/components/autosuggest/autosuggest.vue | 22 +- src/components/avatar_list/avatar_list.vue | 9 +- src/components/basic_user_card/basic_user_card.vue | 41 +- src/components/block_card/block_card.vue | 14 +- src/components/chat_panel/chat_panel.vue | 59 +- src/components/checkbox/checkbox.vue | 9 +- src/components/color_input/color_input.vue | 65 +- src/components/contrast_ratio/contrast_ratio.vue | 52 +- .../conversation-page/conversation-page.vue | 4 +- src/components/conversation/conversation.vue | 27 +- src/components/dialog_modal/dialog_modal.vue | 16 +- src/components/dm_timeline/dm_timeline.vue | 6 +- src/components/emoji-input/emoji-input.vue | 44 +- src/components/export_import/export_import.vue | 33 +- src/components/exporter/exporter.vue | 12 +- src/components/extra_buttons/extra_buttons.vue | 39 +- src/components/favorite_button/favorite_button.vue | 17 +- src/components/features_panel/features_panel.vue | 22 +- src/components/follow_card/follow_card.vue | 19 +- .../follow_request_card/follow_request_card.vue | 14 +- src/components/follow_requests/follow_requests.vue | 9 +- src/components/font_control/font_control.vue | 80 +- .../friends_timeline/friends_timeline.vue | 6 +- src/components/gallery/gallery.vue | 18 +- src/components/image_cropper/image_cropper.vue | 55 +- src/components/importer/importer.vue | 33 +- .../instance_specific_panel.vue | 8 +- src/components/interactions/interactions.vue | 30 +- .../interface_language_switcher.vue | 69 +- src/components/link-preview/link-preview.vue | 18 +- src/components/list/list.vue | 16 +- src/components/login_form/login_form.vue | 114 +-- src/components/media_modal/media_modal.vue | 22 +- src/components/media_upload/media_upload.vue | 30 +- src/components/mentions/mentions.vue | 6 +- src/components/mfa_form/recovery_form.vue | 85 ++- src/components/mfa_form/totp_form.vue | 90 ++- src/components/mobile_nav/mobile_nav.vue | 71 +- .../mobile_post_status_modal.vue | 42 +- .../moderation_tools/moderation_tools.vue | 237 ++++-- src/components/mute_card/mute_card.vue | 14 +- src/components/nav_panel/nav_panel.vue | 17 +- src/components/notification/notification.vue | 97 ++- src/components/notifications/notifications.vue | 66 +- src/components/opacity_input/opacity_input.vue | 58 +- src/components/poll/poll.vue | 39 +- src/components/poll/poll_form.vue | 65 +- .../post_status_form/post_status_form.vue | 363 +++++---- src/components/progress_button/progress_button.vue | 5 +- .../public_and_external_timeline.vue | 6 +- src/components/public_timeline/public_timeline.vue | 6 +- src/components/range_input/range_input.vue | 79 +- src/components/registration/registration.vue | 222 ++++-- src/components/remote_follow/remote_follow.vue | 22 +- src/components/retweet_button/retweet_button.vue | 23 +- src/components/scope_selector/scope_selector.vue | 59 +- src/components/selectable_list/selectable_list.vue | 47 +- src/components/settings/settings.vue | 732 +++++++++++------- src/components/shadow_control/shadow_control.vue | 292 +++++--- src/components/side_drawer/side_drawer.vue | 97 ++- src/components/status/status.vue | 409 +++++++--- src/components/still-image/still-image.vue | 18 +- src/components/style_switcher/preview.vue | 151 ++-- src/components/style_switcher/style_switcher.vue | 825 ++++++++++++++------- src/components/tag_timeline/tag_timeline.vue | 9 +- .../terms_of_service_panel.vue | 6 +- src/components/timeago/timeago.vue | 19 +- src/components/timeline/timeline.vue | 57 +- src/components/user_avatar/user_avatar.vue | 2 +- src/components/user_card/user_card.vue | 360 ++++++--- src/components/user_finder/user_finder.vue | 37 +- src/components/user_panel/user_panel.vue | 20 +- src/components/user_profile/user_profile.vue | 159 ++-- .../user_reporting_modal/user_reporting_modal.vue | 100 ++- src/components/user_search/user_search.vue | 36 +- src/components/user_settings/confirm.vue | 26 +- src/components/user_settings/mfa.vue | 186 +++-- src/components/user_settings/mfa_backup_codes.vue | 24 +- src/components/user_settings/mfa_totp.vue | 56 +- src/components/user_settings/user_settings.vue | 523 +++++++++---- .../video_attachment/video_attachment.vue | 5 +- src/components/who_to_follow/who_to_follow.vue | 9 +- .../who_to_follow_panel/who_to_follow_panel.vue | 17 +- 86 files changed, 4910 insertions(+), 2230 deletions(-) (limited to 'src/components/status') diff --git a/src/App.vue b/src/App.vue index 769e075d..758c9fce 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,53 +1,111 @@