fix draft editing

This commit is contained in:
Henry Jameson 2026-09-02 19:01:56 +03:00
commit 266e711786
4 changed files with 11 additions and 12 deletions

View file

@ -36,6 +36,7 @@ const Draft = {
return {
referenceDraft: cloneDeep(this.draft),
editing: false,
showingForm: false,
showingConfirmDialog: false,
}
},
@ -52,7 +53,7 @@ const Draft = {
}
},
safeToSave() {
return (
return Boolean(
this.draft.status ||
this.draft.files?.length ||
this.draft.hasPoll ||
@ -76,14 +77,9 @@ const Draft = {
},
watch: {
editing(newVal) {
console.log('SAVE?', newVal)
this.showingForm = true
if (newVal) return
console.log('SAVE', newVal)
if (this.safeToSave) {
useDraftsStore().addOrSaveDraft(this.draft)
} else {
useDraftsStore().addOrSaveDraft(this.referenceDraft)
}
this.showingForm = false
},
},
methods: {

View file

@ -64,14 +64,16 @@
</div>
</div>
</div>
<div v-if="editing">
<div v-if="showingForm">
<PostStatusForm
v-if="draft.type !== 'edit'"
ref="postStatusForm"
:hide-draft="true"
v-bind="postStatusFormProps"
/>
<EditStatusForm
v-else
ref="editStatusForm"
:hide-draft="true"
:params="postStatusFormProps"
/>

View file

@ -987,6 +987,8 @@ const PostStatusForm = {
type: this.statusType,
refId: this.refId,
...this.newStatus,
// Draft ID overwrites status ID (which is undefined for fresh statuses)
id: this.draftId,
})
.then((id) => {
if (this.newStatus.id !== id) {

View file

@ -62,14 +62,13 @@ export const useDraftsStore = defineStore('drafts', {
},
async addOrSaveDraft(draft) {
const id = draft.id ?? new Date().getTime().toString()
console.log('SAVE', id)
const draftWithId = { ...draft, id }
this.drafts.set(draft.id, draftWithId)
this.drafts.set(id, draftWithId)
await saveDraftToStorage(draftWithId)
return id
},
async abandonAllDrafts(store) {
const ids = this.drafts.keys()
const ids = [...this.drafts.keys()]
ids.forEach((id) => this.abandonDraft(id))
await deleteDraftFromStorage(ids)
},