akkoma-fe/src/components/post_status_modal/post_status_modal.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

import PostStatusForm from '../post_status_form/post_status_form.vue'
import Modal from '../modal/modal.vue'
import get from 'lodash/get'
const PostStatusModal = {
components: {
PostStatusForm,
Modal
},
data () {
return {
resettingForm: false
}
},
computed: {
isLoggedIn () {
return !!this.$store.state.users.currentUser
},
modalActivated () {
return this.$store.state.postStatus.modalActivated
},
isFormVisible () {
return this.isLoggedIn && !this.resettingForm && this.modalActivated
},
params () {
2019-09-19 18:38:55 +00:00
return this.$store.state.postStatus.params || {}
}
},
2019-09-19 17:52:54 +00:00
watch: {
params (newVal, oldVal) {
2022-09-25 17:50:03 +00:00
if (get(newVal, 'repliedUser.id') !== get(oldVal, 'repliedUser.id') ||
get(newVal, 'statusId') !== get(oldVal, 'statusId')) {
this.resettingForm = true
this.$nextTick(() => {
this.resettingForm = false
})
}
},
isFormVisible (val) {
2019-09-19 17:52:54 +00:00
if (val) {
this.$nextTick(() => this.$el && this.$el.querySelector('textarea').focus())
2019-09-19 17:52:54 +00:00
}
}
},
methods: {
closeModal () {
this.$store.dispatch('closePostStatusModal')
}
}
}
export default PostStatusModal