From 62b2648a3e124ac34d960219b925a6c3569e2229 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 24 Oct 2019 16:53:36 -0400 Subject: split status preview popover into a separate component --- src/components/status_popover/status_popover.js | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/components/status_popover/status_popover.js (limited to 'src/components/status_popover/status_popover.js') diff --git a/src/components/status_popover/status_popover.js b/src/components/status_popover/status_popover.js new file mode 100644 index 00000000..91b64f72 --- /dev/null +++ b/src/components/status_popover/status_popover.js @@ -0,0 +1,43 @@ +import { find } from 'lodash' + +const StatusPopover = { + name: 'StatusPopover', + props: [ + 'statusId' + ], + data () { + return { + preview: null, + popperOptions: { + modifiers: { + preventOverflow: { padding: { top: 50 }, boundariesElement: 'viewport' } + } + } + } + }, + components: { + Status: () => import('../status/status.vue') + }, + methods: { + enter () { + const id = this.statusId + const statuses = this.$store.state.statuses.allStatuses + + if (!this.preview) { + // if we have the status somewhere already + this.preview = find(statuses, { id }) + // or if we have to fetch it + if (!this.preview) { + this.$store.state.api.backendInteractor.fetchStatus({ id }).then((status) => { + this.preview = status + this.$nextTick(this.$refs.popper.updatePopper) + }) + } + } else if (this.preview.id !== id) { + this.preview = find(statuses, 'id') + } + } + } +} + +export default StatusPopover -- cgit v1.2.3-70-g09d2 From e00cf288f54936fc563d2baebf2a694cc3619f61 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 24 Oct 2019 22:14:53 -0400 Subject: refactor status loading logic --- src/components/status_popover/status_popover.js | 24 +++++++++--------------- src/components/status_popover/status_popover.vue | 4 ++-- 2 files changed, 11 insertions(+), 17 deletions(-) (limited to 'src/components/status_popover/status_popover.js') diff --git a/src/components/status_popover/status_popover.js b/src/components/status_popover/status_popover.js index 91b64f72..b96ae642 100644 --- a/src/components/status_popover/status_popover.js +++ b/src/components/status_popover/status_popover.js @@ -7,7 +7,6 @@ const StatusPopover = { ], data () { return { - preview: null, popperOptions: { modifiers: { preventOverflow: { padding: { top: 50 }, boundariesElement: 'viewport' } @@ -15,26 +14,21 @@ const StatusPopover = { } } }, + computed: { + status () { + return find(this.$store.state.statuses.allStatuses, { id: this.statusId }) + } + }, components: { Status: () => import('../status/status.vue') }, methods: { enter () { - const id = this.statusId - const statuses = this.$store.state.statuses.allStatuses - - if (!this.preview) { - // if we have the status somewhere already - this.preview = find(statuses, { id }) - // or if we have to fetch it - if (!this.preview) { - this.$store.state.api.backendInteractor.fetchStatus({ id }).then((status) => { - this.preview = status - this.$nextTick(this.$refs.popper.updatePopper) + if (!this.status) { + this.$store.state.api.backendInteractor.fetchStatus({ id: this.statusId }) + .then((status) => { + this.$store.dispatch('addNewStatuses', { statuses: [status] }) }) - } - } else if (this.preview.id !== id) { - this.preview = find(statuses, 'id') } } } diff --git a/src/components/status_popover/status_popover.vue b/src/components/status_popover/status_popover.vue index b0975afb..62afadca 100644 --- a/src/components/status_popover/status_popover.vue +++ b/src/components/status_popover/status_popover.vue @@ -8,9 +8,9 @@ >
Date: Thu, 24 Oct 2019 22:21:33 -0400 Subject: add fetchStatus action --- src/components/status_popover/status_popover.js | 5 +---- src/modules/statuses.js | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/components/status_popover/status_popover.js') diff --git a/src/components/status_popover/status_popover.js b/src/components/status_popover/status_popover.js index b96ae642..19f16bd9 100644 --- a/src/components/status_popover/status_popover.js +++ b/src/components/status_popover/status_popover.js @@ -25,10 +25,7 @@ const StatusPopover = { methods: { enter () { if (!this.status) { - this.$store.state.api.backendInteractor.fetchStatus({ id: this.statusId }) - .then((status) => { - this.$store.dispatch('addNewStatuses', { statuses: [status] }) - }) + this.$store.dispatch('fetchStatus', this.statusId) } } } diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 918065d2..f11ffdcd 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -537,6 +537,10 @@ const statuses = { setNotificationsSilence ({ rootState, commit }, { value }) { commit('setNotificationsSilence', { value }) }, + fetchStatus ({ rootState, dispatch }, id) { + rootState.api.backendInteractor.fetchStatus({ id }) + .then((status) => dispatch('addNewStatuses', { statuses: [status] })) + }, deleteStatus ({ rootState, commit }, status) { commit('setDeleted', { status }) apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials }) -- cgit v1.2.3-70-g09d2