From 3874fc9b3d8b08daa56f6cd2fc1c32f35fbe3454 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 21 Jul 2018 12:55:40 -0700 Subject: [PATCH] Closes #673 - Redirect to new document after duplicating --- app/menus/DocumentMenu.js | 3 ++- app/models/Document.js | 7 ++++--- app/stores/DocumentsStore.js | 4 +--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/menus/DocumentMenu.js b/app/menus/DocumentMenu.js index 859a05626..1ecec5fca 100644 --- a/app/menus/DocumentMenu.js +++ b/app/menus/DocumentMenu.js @@ -37,7 +37,8 @@ class DocumentMenu extends React.Component { }; handleDuplicate = async (ev: SyntheticEvent<*>) => { - this.props.document.duplicate(); + const duped = await this.props.document.duplicate(); + this.props.history.push(duped.url); }; handlePin = (ev: SyntheticEvent<*>) => { diff --git a/app/models/Document.js b/app/models/Document.js index 1359b7024..e0a5a9b3c 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -4,7 +4,6 @@ import invariant from 'invariant'; import { client } from 'utils/ApiClient'; import stores from 'stores'; -import UiStore from 'stores/UiStore'; import parseTitle from '../../shared/utils/parseTitle'; import unescape from '../../shared/utils/unescape'; @@ -17,7 +16,8 @@ type SaveOptions = { publish?: boolean, done?: boolean, autosave?: boolean }; class Document extends BaseModel { isSaving: boolean = false; hasPendingChanges: boolean = false; - ui: UiStore; + ui: *; + store: *; collaborators: User[]; collection: $Shape; @@ -266,7 +266,7 @@ class Document extends BaseModel { }; duplicate = () => { - this.emit('documents.duplicate', this); + return this.store.duplicate(this); }; download = async () => { @@ -298,6 +298,7 @@ class Document extends BaseModel { this.updateData(data); this.ui = stores.ui; + this.store = stores.documents; } } diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js index 0a33a1c3d..f2ca0a1bd 100644 --- a/app/stores/DocumentsStore.js +++ b/app/stores/DocumentsStore.js @@ -222,6 +222,7 @@ class DocumentsStore extends BaseStore { id: duped.id, collectionId: duped.collection.id, }); + return duped; } }; @@ -257,9 +258,6 @@ class DocumentsStore extends BaseStore { this.on('documents.create', (data: Document) => { this.add(data); }); - this.on('documents.duplicate', (data: Document) => { - this.duplicate(data); - }); // Re-fetch dashboard content so that we don't show deleted documents this.on('collections.delete', () => {