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/main.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/main.js') diff --git a/src/main.js b/src/main.js index 5758c7bd..d0f2674b 100644 --- a/src/main.js +++ b/src/main.js @@ -15,7 +15,6 @@ import mediaViewerModule from './modules/media_viewer.js' import oauthTokensModule from './modules/oauth_tokens.js' import reportsModule from './modules/reports.js' -import VueTimeago from 'vue-timeago' import VueI18n from 'vue-i18n' import createPersistedState from './lib/persisted_state.js' @@ -33,14 +32,6 @@ const currentLocale = (window.navigator.language || 'en').split('-')[0] Vue.use(Vuex) Vue.use(VueRouter) -Vue.use(VueTimeago, { - locale: currentLocale === 'cs' ? 'cs' : currentLocale === 'ja' ? 'ja' : 'en', - locales: { - 'cs': require('../static/timeago-cs.json'), - 'en': require('../static/timeago-en.json'), - 'ja': require('../static/timeago-ja.json') - } -}) Vue.use(VueI18n) Vue.use(VueChatScroll) Vue.use(VueClickOutside) -- cgit v1.2.3-70-g09d2 From e5e9bb27f3a0825b695684a503ea7e5e75073734 Mon Sep 17 00:00:00 2001 From: Shpuld Shpludson 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/main.js') 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 1727c815f8bb9651a687d4329c4e7e13b7f1983d Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 11 Jul 2019 08:30:35 -0400 Subject: install v-tooltip --- package.json | 3 ++- src/main.js | 2 ++ yarn.lock | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/main.js') diff --git a/package.json b/package.json index 25bc419c..f1fdaf49 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "portal-vue": "^2.1.4", "sanitize-html": "^1.13.0", "v-click-outside": "^2.1.1", + "v-tooltip": "^2.0.2", "vue": "^2.5.13", "vue-chat-scroll": "^1.2.1", "vue-i18n": "^7.3.2", @@ -81,8 +82,8 @@ "json-loader": "^0.5.4", "karma": "^3.0.0", "karma-coverage": "^1.1.1", - "karma-mocha": "^1.2.0", "karma-firefox-launcher": "^1.1.0", + "karma-mocha": "^1.2.0", "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.26", diff --git a/src/main.js b/src/main.js index 3287fa2b..b3256e8e 100644 --- a/src/main.js +++ b/src/main.js @@ -26,6 +26,7 @@ import messages from './i18n/messages.js' import VueChatScroll from 'vue-chat-scroll' import VueClickOutside from 'v-click-outside' import PortalVue from 'portal-vue' +import VTooltip from 'v-tooltip' import afterStoreSetup from './boot/after_store.js' @@ -37,6 +38,7 @@ Vue.use(VueI18n) Vue.use(VueChatScroll) Vue.use(VueClickOutside) Vue.use(PortalVue) +Vue.use(VTooltip) const i18n = new VueI18n({ // By default, use the browser locale, we will update it if neccessary diff --git a/yarn.lock b/yarn.lock index 5a84499e..2656ef3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5463,6 +5463,11 @@ popper.js@^1.14.7: version "1.14.7" resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.14.7.tgz#e31ec06cfac6a97a53280c3e55e4e0c860e7738e" +popper.js@^1.15.0: + version "1.15.0" + resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.15.0.tgz#5560b99bbad7647e9faa475c6b8056621f5a4ff2" + integrity sha512-w010cY1oCUmI+9KwwlWki+r5jxKfTFDVoadl7MSrIujHU5MJ5OR6HTDj6Xo8aoR/QsA56x8jKjA59qGH4ELtrA== + portal-vue@^2.1.4: version "2.1.4" resolved "https://registry.yarnpkg.com/portal-vue/-/portal-vue-2.1.4.tgz#1fc679d77e294dc8d026f1eb84aa467de11b392e" @@ -7198,6 +7203,15 @@ v-click-outside@^2.1.1: version "2.1.3" resolved "https://registry.yarnpkg.com/v-click-outside/-/v-click-outside-2.1.3.tgz#b7297abe833a439dc0895e6418a494381e64b5e7" +v-tooltip@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/v-tooltip/-/v-tooltip-2.0.2.tgz#8610d9eece2cc44fd66c12ef2f12eec6435cab9b" + integrity sha512-xQ+qzOFfywkLdjHknRPgMMupQNS8yJtf9Utd5Dxiu/0n4HtrxqsgDtN2MLZ0LKbburtSAQgyypuE/snM8bBZhw== + dependencies: + lodash "^4.17.11" + popper.js "^1.15.0" + vue-resize "^0.4.5" + validate-npm-package-license@^3.0.1: version "3.0.4" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a" @@ -7278,6 +7292,11 @@ vue-popperjs@^2.0.3: dependencies: popper.js "^1.14.7" +vue-resize@^0.4.5: + version "0.4.5" + resolved "https://registry.yarnpkg.com/vue-resize/-/vue-resize-0.4.5.tgz#4777a23042e3c05620d9cbda01c0b3cc5e32dcea" + integrity sha512-bhP7MlgJQ8TIkZJXAfDf78uJO+mEI3CaLABLjv0WNzr4CcGRGPIAItyWYnP6LsPA4Oq0WE+suidNs6dgpO4RHg== + vue-router@^3.0.1: version "3.0.2" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.2.tgz#dedc67afe6c4e2bc25682c8b1c2a8c0d7c7e56be" -- cgit v1.2.3-70-g09d2