pleroma-fe/src/components/draft/draft.js

100 lines
2.4 KiB
JavaScript
Raw Normal View History

2026-01-06 16:23:17 +02:00
import { cloneDeep } from 'lodash'
2026-01-08 17:26:52 +02:00
2026-01-06 16:23:17 +02:00
import ConfirmModal from 'src/components/confirm_modal/confirm_modal.vue'
import EditStatusForm from 'src/components/edit_status_form/edit_status_form.vue'
import Gallery from 'src/components/gallery/gallery.vue'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
import StatusContent from 'src/components/status_content/status_content.vue'
2024-12-31 12:52:29 +02:00
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import { faPollH } from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faPollH)
2024-12-31 12:52:29 +02:00
2023-03-10 12:10:39 -05:00
const Draft = {
components: {
2023-03-10 12:39:08 -05:00
PostStatusForm,
2023-03-10 19:24:01 -05:00
EditStatusForm,
ConfirmModal,
2024-12-30 02:07:49 +02:00
StatusContent,
2026-01-06 16:22:52 +02:00
Gallery,
2023-03-10 12:10:39 -05:00
},
props: {
draft: {
type: Object,
2026-01-06 16:22:52 +02:00
required: true,
},
2023-03-10 12:10:39 -05:00
},
2026-01-06 16:22:52 +02:00
data() {
2023-03-10 12:10:39 -05:00
return {
referenceDraft: cloneDeep(this.draft),
2023-03-10 12:39:08 -05:00
editing: false,
2026-01-06 16:22:52 +02:00
showingConfirmDialog: false,
2023-03-10 12:10:39 -05:00
}
},
computed: {
2026-01-06 16:22:52 +02:00
relAttrs() {
2023-03-10 12:10:39 -05:00
if (this.draft.type === 'edit') {
return { statusId: this.draft.refId }
} else if (this.draft.type === 'reply') {
return { replyTo: this.draft.refId }
} else {
return {}
}
},
2026-01-06 16:22:52 +02:00
safeToSave() {
return this.draft.status || this.draft.files?.length || this.draft.hasPoll
},
2026-01-06 16:22:52 +02:00
postStatusFormProps() {
2023-03-10 12:10:39 -05:00
return {
draftId: this.draft.id,
2026-01-06 16:22:52 +02:00
...this.relAttrs,
2023-03-10 12:10:39 -05:00
}
},
2026-01-06 16:22:52 +02:00
refStatus() {
return this.draft.refId
? this.$store.state.statuses.allStatusesObject[this.draft.refId]
: undefined
2024-12-30 02:07:49 +02:00
},
2026-01-06 16:22:52 +02:00
localCollapseSubjectDefault() {
2024-12-30 02:07:49 +02:00
return this.$store.getters.mergedConfig.collapseMessageWithSubject
},
2026-01-06 16:22:52 +02:00
nsfwClickthrough() {
2024-12-30 02:07:49 +02:00
if (!this.draft.nsfw) {
return false
}
if (this.draft.summary && this.localCollapseSubjectDefault) {
return false
}
return true
2026-01-06 16:22:52 +02:00
},
2023-03-10 12:10:39 -05:00
},
watch: {
2026-01-06 16:22:52 +02:00
editing(newVal) {
if (newVal) return
if (this.safeToSave) {
this.$store.dispatch('addOrSaveDraft', { draft: this.draft })
} else {
this.$store.dispatch('addOrSaveDraft', { draft: this.referenceDraft })
}
2026-01-06 16:22:52 +02:00
},
},
2023-03-10 12:10:39 -05:00
methods: {
2026-01-06 16:22:52 +02:00
toggleEditing() {
2023-03-10 12:10:39 -05:00
this.editing = !this.editing
2023-03-10 12:39:08 -05:00
},
2026-01-06 16:22:52 +02:00
abandon() {
2023-03-10 12:39:08 -05:00
this.showingConfirmDialog = true
},
2026-01-06 16:22:52 +02:00
doAbandon() {
this.$store.dispatch('abandonDraft', { id: this.draft.id }).then(() => {
this.hideConfirmDialog()
})
2023-03-10 12:39:08 -05:00
},
2026-01-06 16:22:52 +02:00
hideConfirmDialog() {
2023-03-10 12:39:08 -05:00
this.showingConfirmDialog = false
2026-01-06 16:22:52 +02:00
},
},
2023-03-10 12:10:39 -05:00
}
export default Draft