diff options
| author | tusooa <tusooa@kazv.moe> | 2022-09-11 18:08:00 +0000 |
|---|---|---|
| committer | tusooa <tusooa@kazv.moe> | 2022-09-11 18:08:00 +0000 |
| commit | 2bea5d81288dcf4e231d557b5f1ef338fc1f78f6 (patch) | |
| tree | 67515a1ae88f74a88763a5e769a49ce6715ba73f /src/components/edit_status_modal/edit_status_modal.js | |
| parent | de40ebd5ea9c3a89c85d822ee719dce9b48c451a (diff) | |
| parent | ee58e3868c2d58b889d8a32c1b6dfd3732df7584 (diff) | |
Merge branch 'add/edit-status' into 'develop'
Add edit status functionality
See merge request pleroma/pleroma-fe!1537
Diffstat (limited to 'src/components/edit_status_modal/edit_status_modal.js')
| -rw-r--r-- | src/components/edit_status_modal/edit_status_modal.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/components/edit_status_modal/edit_status_modal.js b/src/components/edit_status_modal/edit_status_modal.js new file mode 100644 index 00000000..75adfea7 --- /dev/null +++ b/src/components/edit_status_modal/edit_status_modal.js @@ -0,0 +1,75 @@ +import PostStatusForm from '../post_status_form/post_status_form.vue' +import Modal from '../modal/modal.vue' +import statusPosterService from '../../services/status_poster/status_poster.service.js' +import get from 'lodash/get' + +const EditStatusModal = { + components: { + PostStatusForm, + Modal + }, + data () { + return { + resettingForm: false + } + }, + computed: { + isLoggedIn () { + return !!this.$store.state.users.currentUser + }, + modalActivated () { + return this.$store.state.editStatus.modalActivated + }, + isFormVisible () { + return this.isLoggedIn && !this.resettingForm && this.modalActivated + }, + params () { + return this.$store.state.editStatus.params || {} + } + }, + watch: { + params (newVal, oldVal) { + if (get(newVal, 'statusId') !== get(oldVal, 'statusId')) { + this.resettingForm = true + this.$nextTick(() => { + this.resettingForm = false + }) + } + }, + isFormVisible (val) { + if (val) { + this.$nextTick(() => this.$el && this.$el.querySelector('textarea').focus()) + } + } + }, + methods: { + doEditStatus ({ status, spoilerText, sensitive, media, contentType, poll }) { + const params = { + store: this.$store, + statusId: this.$store.state.editStatus.params.statusId, + status, + spoilerText, + sensitive, + poll, + media, + contentType + } + + return statusPosterService.editStatus(params) + .then((data) => { + return data + }) + .catch((err) => { + console.error('Error editing status', err) + return { + error: err.message + } + }) + }, + closeModal () { + this.$store.dispatch('closeEditStatusModal') + } + } +} + +export default EditStatusModal |
