Skip to content

Commit

Permalink
process auto save from editor extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sofyenne committed Oct 9, 2024
1 parent 145b937 commit bb017f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default {
saveButtonIcon: 'fas fa-save',
translationSwitch: false,
newTranslation: false,
autosaveProcessedFromEditorExtension: false
};
},
computed: {
Expand Down Expand Up @@ -195,6 +196,7 @@ export default {
document.addEventListener('automatic-translation-extensions-updated', () => {
this.refreshTranslationExtensions();
});
document.addEventListener('note-editor-extensions-data-updated', (evt) => this.processAutoSaveFromEditorExtension(evt));
this.getAvailableLanguages();
window.addEventListener('beforeunload', () => {
if (!this.postingNote && this.note.draftPage && this.note.id) {
Expand Down Expand Up @@ -248,6 +250,13 @@ export default {
});
},
methods: {
processAutoSaveFromEditorExtension(event) {
if (event.detail.processAutoSave) {
this.autosaveProcessedFromEditorExtension = true;
this.draftSavingStatus = this.$t('notes.draft.savingDraftStatus');
this.persistDraftNote(this.fillDraftNote(), true);
}
},
editorClosed() {
window.close();
},
Expand Down Expand Up @@ -361,13 +370,7 @@ export default {
});
}).finally(() => this.enableClickOnce());
},
autoSave(event) {
if (event?.detail?.processAutoSave) {
//TODO
}
if (event?.detail?.showAutoSaveMessage) {
this.draftSavingStatus = this.$t('notes.draft.savingDraftStatus');
}
autoSave() {
if (this.translationSwitch) {
return;
}
Expand Down Expand Up @@ -586,6 +589,14 @@ export default {
this.savingDraft = false;
setTimeout(() => {
this.draftSavingStatus = this.$t('notes.draft.savedDraftStatus');
if (this.autosaveProcessedFromEditorExtension) {
document.dispatchEvent(new CustomEvent('note-draft-auto-save-done', {
detail: {
draftId: this.note.id
}
}));
}
this.autosaveProcessedFromEditorExtension = false;
}, this.autoSaveDelay/2);
}).catch(e => {
console.error('Error when creating draft note: ', e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ export default {
},
watch: {
'noteObject.title': function(newVal, oldVal) {
if (newVal && newVal.length > this.noteTitleMaxLength) {
this.displayNoteTitleMaxLengthCheckAlert();
this.noteObject.title = oldVal;
}
this.displayNoteTitleMaxLengthCheckAlert(newVal, oldVal);
this.updateData();
},
Expand Down Expand Up @@ -247,12 +251,13 @@ export default {
},
computed: {
extensionParams() {
console.log(this.note);
return {
spaceId: this.getURLQueryParam('spaceId'),
entityId: this.note.draftPage && this.note?.id || this.note.latestVersionId,
entityType: this.note.draftPage && 'WIKI_DRAFT_PAGES' || 'WIKI_PAGE_VERSIONS',
lang: this.note.lang,
isEmptyNoteTranslation: this.note?.lang && this.note?.title && this.note?.content
isEmptyNoteTranslation: this.note.lang != null && !this.note?.title && !this.note?.content
};
},
hasFeaturedImage() {
Expand Down Expand Up @@ -285,14 +290,8 @@ export default {
document.addEventListener('note-custom-plugins', this.openCustomPluginsDrawer);
document.addEventListener('notes-editor-extensions-updated', this.refreshEditorExtensions);
document.addEventListener('editor-extensions-data-start-updating', (event) => this.handleEditorExtensionDataUpdated(event));
document.addEventListener('editor-extensions-data-updated', (event) => this.handleEditorExtensionDataUpdated(event));
},
methods: {
handleEditorExtensionDataUpdated(event) {
this.autoSave(event.detail);
},
metadataUpdated(properties) {
this.updatingProperties = true;
this.noteObject.properties = properties;
Expand Down Expand Up @@ -575,12 +574,6 @@ export default {
isImageDrawerClosed() {
return this.$refs.featuredImageDrawer.isClosed();
},
openPublicationDrawer() {
this.$refs.editorPublicationDrawer.open(this.noteObject);
},
publicationDrawerClosed() {
this.enablePostKeys ++;
},
openMetadataDrawer() {
this.$refs.editorMetadataDrawer.open(this.noteObject);
},
Expand Down

0 comments on commit bb017f5

Please sign in to comment.