From f4bbf1d4e205e3c3438226d0cf71e77d4bc0be11 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 19 Sep 2019 13:27:37 -0400 Subject: add new module and modal to post new status --- .../post_status_modal/post_status_modal.js | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/components/post_status_modal/post_status_modal.js (limited to 'src/components/post_status_modal/post_status_modal.js') diff --git a/src/components/post_status_modal/post_status_modal.js b/src/components/post_status_modal/post_status_modal.js new file mode 100644 index 00000000..86a4e1d8 --- /dev/null +++ b/src/components/post_status_modal/post_status_modal.js @@ -0,0 +1,25 @@ +import PostStatusForm from '../post_status_form/post_status_form.vue' + +const PostStatusModal = { + components: { + PostStatusForm + }, + computed: { + isLoggedIn () { + return !!this.$store.state.users.currentUser + }, + isOpen () { + return this.isLoggedIn && this.$store.state.postStatus.modalActivated + }, + params () { + return this.$store.state.postStatus.params + } + }, + methods: { + closeModal () { + this.$store.dispatch('closePostStatusModal') + } + } +} + +export default PostStatusModal -- cgit v1.2.3-70-g09d2 From 0c8038d4f610bd7260b920e6fb55a8ea0341d291 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 19 Sep 2019 13:52:54 -0400 Subject: recover autofocusing behavior --- src/components/post_status_modal/post_status_modal.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/components/post_status_modal/post_status_modal.js') diff --git a/src/components/post_status_modal/post_status_modal.js b/src/components/post_status_modal/post_status_modal.js index 86a4e1d8..15783642 100644 --- a/src/components/post_status_modal/post_status_modal.js +++ b/src/components/post_status_modal/post_status_modal.js @@ -15,6 +15,13 @@ const PostStatusModal = { return this.$store.state.postStatus.params } }, + watch: { + isOpen (val) { + if (val) { + this.$nextTick(() => this.$el.querySelector('textarea').focus()) + } + } + }, methods: { closeModal () { this.$store.dispatch('closePostStatusModal') -- cgit v1.2.3-70-g09d2 From c8a18f387c28d5f895c1e727b0d040da96dcebc1 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 19 Sep 2019 14:38:55 -0400 Subject: wire up props with PostStatusModal --- src/components/post_status_form/post_status_form.js | 2 +- src/components/post_status_modal/post_status_modal.js | 2 +- src/components/post_status_modal/post_status_modal.vue | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/components/post_status_modal/post_status_modal.js') diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 40bbf6d4..dc4b419c 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -8,7 +8,7 @@ import fileTypeService from '../../services/file_type/file_type.service.js' import { reject, map, uniqBy } from 'lodash' import suggestor from '../emoji-input/suggestor.js' -const buildMentionsString = ({ user, attentions }, currentUser) => { +const buildMentionsString = ({ user, attentions = [] }, currentUser) => { let allAttentions = [...attentions] allAttentions.unshift(user) diff --git a/src/components/post_status_modal/post_status_modal.js b/src/components/post_status_modal/post_status_modal.js index 15783642..1033ba11 100644 --- a/src/components/post_status_modal/post_status_modal.js +++ b/src/components/post_status_modal/post_status_modal.js @@ -12,7 +12,7 @@ const PostStatusModal = { return this.isLoggedIn && this.$store.state.postStatus.modalActivated }, params () { - return this.$store.state.postStatus.params + return this.$store.state.postStatus.params || {} } }, watch: { diff --git a/src/components/post_status_modal/post_status_modal.vue b/src/components/post_status_modal/post_status_modal.vue index 85a5401c..3f8eec69 100644 --- a/src/components/post_status_modal/post_status_modal.vue +++ b/src/components/post_status_modal/post_status_modal.vue @@ -13,6 +13,7 @@ -- cgit v1.2.3-70-g09d2 From 50d9ed00078e400ccd0ddc2ca38044c1fe70c1db Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 28 Sep 2019 16:35:39 -0400 Subject: reset post status form only when reply user is changed --- .../post_status_modal/post_status_modal.js | 25 ++++++++++++++++++---- .../post_status_modal/post_status_modal.vue | 3 ++- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src/components/post_status_modal/post_status_modal.js') diff --git a/src/components/post_status_modal/post_status_modal.js b/src/components/post_status_modal/post_status_modal.js index 1033ba11..38258296 100644 --- a/src/components/post_status_modal/post_status_modal.js +++ b/src/components/post_status_modal/post_status_modal.js @@ -1,24 +1,41 @@ import PostStatusForm from '../post_status_form/post_status_form.vue' +import get from 'lodash/get' const PostStatusModal = { components: { PostStatusForm }, + data () { + return { + resettingForm: false + } + }, computed: { isLoggedIn () { return !!this.$store.state.users.currentUser }, - isOpen () { - return this.isLoggedIn && this.$store.state.postStatus.modalActivated + modalActivated () { + return this.$store.state.postStatus.modalActivated + }, + isFormVisible () { + return this.isLoggedIn && !this.resettingForm && this.modalActivated }, params () { return this.$store.state.postStatus.params || {} } }, watch: { - isOpen (val) { + params (newVal, oldVal) { + if (get(newVal, 'repliedUser.id') !== get(oldVal, 'repliedUser.id')) { + this.resettingForm = true + this.$nextTick(() => { + this.resettingForm = false + }) + } + }, + isFormVisible (val) { if (val) { - this.$nextTick(() => this.$el.querySelector('textarea').focus()) + this.$nextTick(() => this.$el && this.$el.querySelector('textarea').focus()) } } }, diff --git a/src/components/post_status_modal/post_status_modal.vue b/src/components/post_status_modal/post_status_modal.vue index 3f8eec69..d3a82389 100644 --- a/src/components/post_status_modal/post_status_modal.vue +++ b/src/components/post_status_modal/post_status_modal.vue @@ -1,6 +1,7 @@