Skip to content

Commit

Permalink
feat: Disable the save/publish button when draft status is saving - E…
Browse files Browse the repository at this point in the history
…XO-74280 - Meeds-io/MIPs#129 (#235)
  • Loading branch information
sofyenne committed Sep 20, 2024
1 parent 3979d7c commit 0438c49
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default {
},
disableSaveButton() {
return this.postingNews || !this.article.title
|| this.isEmptyArticleContent
|| this.savingDraft
|| (!this.propertiesModified
&& this.articleNotChanged
&& this.article.publicationState !== 'draft');
Expand All @@ -172,9 +172,6 @@ export default {
return this.originalArticle?.title === this.article.title && this.isSameArticleContent()
&& !this.propertiesModified;
},
isEmptyArticleContent() {
return this.article.content === '' || Array.from(new DOMParser().parseFromString(this.article.content, 'text/html').body.childNodes).every(node => (node.nodeName === 'P' && !node.textContent.trim() && node.children.length === 0) || (node.nodeType === Node.TEXT_NODE && !node.textContent.trim()));
},
propertiesModified() {
return JSON.stringify(this.article?.properties) !== JSON.stringify(this.originalArticle?.properties);
},
Expand Down Expand Up @@ -303,6 +300,7 @@ export default {
}).then(() => this.$emit('draftUpdated'))
.then(() => this.draftSavingStatus = this.$t('news.composer.draft.savedDraftStatus'))
.finally(() => {
this.savingDraft = false;
this.enableClickOnce();
if (this.articleType === 'latest_draft' && this.selectedLanguage) {
this.updateUrl();
Expand Down Expand Up @@ -378,14 +376,19 @@ export default {
this.article.draftPage = true;
})
.then(() => this.$emit('draftUpdated'))
.then(() => this.draftSavingStatus = this.$t('news.composer.draft.savedDraftStatus'));
.then(() => {
this.draftSavingStatus = this.$t('news.composer.draft.savedDraftStatus');
this.savingDraft = false;
});
} else {
this.$newsServices.deleteDraft(this.article.id)
.then(() => this.$emit('draftDeleted'))
.then(() => this.draftSavingStatus = this.$t('news.composer.draft.savedDraftStatus'));
.then(() => {
this.draftSavingStatus = this.$t('news.composer.draft.savedDraftStatus');
this.savingDraft = false;
});
this.article.id = null;
}
this.savingDraft = false;
} else if (this.article.title || this.article.body) {
article.publicationState = 'draft';
this.$newsServices.saveNews(article).then((createdArticle) => {
Expand All @@ -396,8 +399,8 @@ export default {
if (!this.articleId) {
this.articleId = createdArticle.id;
}
this.savingDraft = false;
this.$emit('draftCreated');
this.savingDraft = false;
});
} else {
this.draftSavingStatus = '';
Expand Down

0 comments on commit 0438c49

Please sign in to comment.