fix draft editing
This commit is contained in:
parent
e9b70fcb0e
commit
266e711786
4 changed files with 11 additions and 12 deletions
|
|
@ -36,6 +36,7 @@ const Draft = {
|
||||||
return {
|
return {
|
||||||
referenceDraft: cloneDeep(this.draft),
|
referenceDraft: cloneDeep(this.draft),
|
||||||
editing: false,
|
editing: false,
|
||||||
|
showingForm: false,
|
||||||
showingConfirmDialog: false,
|
showingConfirmDialog: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -52,7 +53,7 @@ const Draft = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
safeToSave() {
|
safeToSave() {
|
||||||
return (
|
return Boolean(
|
||||||
this.draft.status ||
|
this.draft.status ||
|
||||||
this.draft.files?.length ||
|
this.draft.files?.length ||
|
||||||
this.draft.hasPoll ||
|
this.draft.hasPoll ||
|
||||||
|
|
@ -76,14 +77,9 @@ const Draft = {
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
editing(newVal) {
|
editing(newVal) {
|
||||||
console.log('SAVE?', newVal)
|
this.showingForm = true
|
||||||
if (newVal) return
|
if (newVal) return
|
||||||
console.log('SAVE', newVal)
|
this.showingForm = false
|
||||||
if (this.safeToSave) {
|
|
||||||
useDraftsStore().addOrSaveDraft(this.draft)
|
|
||||||
} else {
|
|
||||||
useDraftsStore().addOrSaveDraft(this.referenceDraft)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
||||||
|
|
@ -64,14 +64,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="editing">
|
<div v-if="showingForm">
|
||||||
<PostStatusForm
|
<PostStatusForm
|
||||||
v-if="draft.type !== 'edit'"
|
v-if="draft.type !== 'edit'"
|
||||||
|
ref="postStatusForm"
|
||||||
:hide-draft="true"
|
:hide-draft="true"
|
||||||
v-bind="postStatusFormProps"
|
v-bind="postStatusFormProps"
|
||||||
/>
|
/>
|
||||||
<EditStatusForm
|
<EditStatusForm
|
||||||
v-else
|
v-else
|
||||||
|
ref="editStatusForm"
|
||||||
:hide-draft="true"
|
:hide-draft="true"
|
||||||
:params="postStatusFormProps"
|
:params="postStatusFormProps"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -987,6 +987,8 @@ const PostStatusForm = {
|
||||||
type: this.statusType,
|
type: this.statusType,
|
||||||
refId: this.refId,
|
refId: this.refId,
|
||||||
...this.newStatus,
|
...this.newStatus,
|
||||||
|
// Draft ID overwrites status ID (which is undefined for fresh statuses)
|
||||||
|
id: this.draftId,
|
||||||
})
|
})
|
||||||
.then((id) => {
|
.then((id) => {
|
||||||
if (this.newStatus.id !== id) {
|
if (this.newStatus.id !== id) {
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,13 @@ export const useDraftsStore = defineStore('drafts', {
|
||||||
},
|
},
|
||||||
async addOrSaveDraft(draft) {
|
async addOrSaveDraft(draft) {
|
||||||
const id = draft.id ?? new Date().getTime().toString()
|
const id = draft.id ?? new Date().getTime().toString()
|
||||||
console.log('SAVE', id)
|
|
||||||
const draftWithId = { ...draft, id }
|
const draftWithId = { ...draft, id }
|
||||||
this.drafts.set(draft.id, draftWithId)
|
this.drafts.set(id, draftWithId)
|
||||||
await saveDraftToStorage(draftWithId)
|
await saveDraftToStorage(draftWithId)
|
||||||
return id
|
return id
|
||||||
},
|
},
|
||||||
async abandonAllDrafts(store) {
|
async abandonAllDrafts(store) {
|
||||||
const ids = this.drafts.keys()
|
const ids = [...this.drafts.keys()]
|
||||||
ids.forEach((id) => this.abandonDraft(id))
|
ids.forEach((id) => this.abandonDraft(id))
|
||||||
await deleteDraftFromStorage(ids)
|
await deleteDraftFromStorage(ids)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue