From c6537279ba85fb2f3a356b8841e6657aa1be8862 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 22 Oct 2017 22:20:53 -0700 Subject: [PATCH] Fixes for empty document --- frontend/components/Editor/Editor.js | 2 +- server/presenters/document.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/components/Editor/Editor.js b/frontend/components/Editor/Editor.js index 6a99e730..659cb4b2 100644 --- a/frontend/components/Editor/Editor.js +++ b/frontend/components/Editor/Editor.js @@ -51,7 +51,7 @@ type KeyData = { onImageUploadStop: props.onImageUploadStop, }); - if (props.text) { + if (props.text.trim().length) { this.state = { state: Markdown.deserialize(props.text) }; } else { this.state = { state: Plain.deserialize('') }; diff --git a/server/presenters/document.js b/server/presenters/document.js index bf483cd1..575d18f3 100644 --- a/server/presenters/document.js +++ b/server/presenters/document.js @@ -14,6 +14,11 @@ async function present(ctx: Object, document: Document, options: ?Options) { ...options, }; ctx.cache.set(document.id, document); + + // For empty document content, return the title + if (document.text.trim().length === 0) + document.text = `# ${document.title || 'Untitled document'}`; + const data = { id: document.id, url: document.getUrl(),