diff --git a/app/models/Document.js b/app/models/Document.js index 55c102960..271f6ab96 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -72,17 +72,6 @@ export default class Document extends BaseModel { return !this.publishedAt; } - @computed - get isEmpty(): boolean { - // Check if the document title has been modified and user generated content exists - return this.text.replace(/^#/, '').trim().length === 0; - } - - @computed - get allowSave(): boolean { - return !this.isEmpty && !this.isSaving; - } - @action share = async () => { const res = await client.post('/shares.create', { documentId: this.id }); diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index fc0c90fc5..502eddbee 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -79,6 +79,7 @@ class DocumentScene extends React.Component { @observable isSaving: boolean = false; @observable isPublishing: boolean = false; @observable isDirty: boolean = false; + @observable isEmpty: boolean = true; @observable notFound: boolean = false; @observable moveModalOpen: boolean = false; @@ -166,6 +167,7 @@ class DocumentScene extends React.Component { } this.isDirty = false; + this.isEmpty = false; const document = this.document; @@ -226,17 +228,19 @@ class DocumentScene extends React.Component { let document = this.document; if (!document) return; + // prevent saves when we're already saving + if (document.isSaving ) return; + // get the latest version of the editor text value const text = this.getEditorText ? this.getEditorText() : document.text; + // prevent save before anything has been written + if (text.trim() === "#") return; + // prevent autosave if nothing has changed if (options.autosave && document.text.trim() === text.trim()) return; document.text = text; - if (!document.allowSave) return; - - // prevent autosave before anything has been written - if (options.autosave && !document.title && !document.id) return; let isNew = !document.id; this.isSaving = true; @@ -261,9 +265,15 @@ class DocumentScene extends React.Component { updateIsDirty = debounce(() => { const document = this.document; + const editorText = this.getEditorText().trim() + + this.isEmpty = editorText === "#"; + this.isDirty = !!document && editorText !== document.text.trim() + + console.log({editorText}) + console.log({doctext: document.text.trim()}) + - this.isDirty = - !!document && this.getEditorText().trim() !== document.text.trim(); }, IS_DIRTY_DELAY); onImageUploadStart = () => { @@ -377,7 +387,8 @@ class DocumentScene extends React.Component { isEditing={this.isEditing} isSaving={this.isSaving} isPublishing={this.isPublishing} - savingIsDisabled={!document.allowSave} + publishingIsDisabled={document.isSaving || this.isPublishing || this.isEmpty} + savingIsDisabled={document.isSaving || this.isEmpty} onDiscard={this.onDiscard} onSave={this.onSave} /> diff --git a/app/scenes/Document/components/Header.js b/app/scenes/Document/components/Header.js index c42efc5d1..7b7871d92 100644 --- a/app/scenes/Document/components/Header.js +++ b/app/scenes/Document/components/Header.js @@ -30,6 +30,7 @@ type Props = { isEditing: boolean, isSaving: boolean, isPublishing: boolean, + publishingIsDisabled: boolean, savingIsDisabled: boolean, onDiscard: () => *, onSave: ({ @@ -99,6 +100,7 @@ class Header extends React.Component { isPublishing, isSaving, savingIsDisabled, + publishingIsDisabled, auth, } = this.props; const canShareDocuments = @@ -171,7 +173,7 @@ class Header extends React.Component {