diff --git a/app/models/Document.ts b/app/models/Document.ts index 6f4d29071..5a30393c1 100644 --- a/app/models/Document.ts +++ b/app/models/Document.ts @@ -172,6 +172,11 @@ export default class Document extends BaseModel { return !this.publishedAt; } + @computed + get hasEmptyTitle(): boolean { + return this.title === ""; + } + @computed get titleWithDefault(): string { return this.title || "Untitled"; diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index 8c71a976f..cbf943cb9 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -138,6 +138,19 @@ class DocumentScene extends React.Component { } } + 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 { 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);