From e6f99bc3fb87f5dcf7d6298982080b3d4ca3719e Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Tue, 12 Sep 2017 20:48:33 -0700 Subject: [PATCH] Added edit cache for canceling edit changes --- frontend/scenes/Document/Document.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index e55a15e0c..fea42c427 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -41,6 +41,7 @@ type Props = { props: Props; savedTimeout: number; + @observable editCache: ?string; @observable newDocument: ?Document; @observable isDragging = false; @observable isLoading = false; @@ -86,6 +87,8 @@ type Props = { if (document) { this.props.ui.setActiveDocument(document); + // Cache data if user enters edit mode and cancels + this.editCache = document.text; document.view(); } else { // Render 404 with search @@ -104,6 +107,7 @@ type Props = { onClickEdit = () => { if (!this.document) return; const url = `${this.document.url}/edit`; + this.editCache = document.text; this.props.history.push(url); }; @@ -152,7 +156,7 @@ type Props = { let url; if (this.document && this.document.url) { url = this.document.url; - await this.document.fetch(); + if (this.editCache) this.document.updateData({ text: this.editCache }); } else { url = collectionUrl(this.props.match.params.id); }