fix: Cleanup totally empty drafts on leave (#3310)
* fix: Cleanup totally empty drafts on leave * cleanup * fix: Add check the doc has never been saved after creation when auto-deleting
This commit is contained in:
@@ -138,6 +138,19 @@ class DocumentScene extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (
|
||||
this.isEmpty &&
|
||||
this.props.document.createdBy.id === this.props.auth.user?.id &&
|
||||
this.props.document.isDraft &&
|
||||
this.props.document.isActive &&
|
||||
this.props.document.hasEmptyTitle &&
|
||||
this.props.document.isPersistedOnce
|
||||
) {
|
||||
this.props.document.delete();
|
||||
}
|
||||
}
|
||||
|
||||
replaceDocument = (template: Document | Revision) => {
|
||||
const editorRef = this.editor.current;
|
||||
|
||||
@@ -341,7 +354,8 @@ class DocumentScene extends React.Component<Props> {
|
||||
this.isEditorDirty = editorText !== document.text.trim();
|
||||
|
||||
// a single hash is a doc with just an empty title
|
||||
this.isEmpty = (!editorText || editorText === "#") && !this.title;
|
||||
this.isEmpty =
|
||||
(!editorText || editorText === "#" || editorText === "\\") && !this.title;
|
||||
};
|
||||
|
||||
updateIsDirtyDebounced = debounce(this.updateIsDirty, 500);
|
||||
|
||||
Reference in New Issue
Block a user