Closes #673 - Redirect to new document after duplicating

This commit is contained in:
Tom Moor
2018-07-21 12:55:40 -07:00
parent 28690be77c
commit 3874fc9b3d
3 changed files with 7 additions and 7 deletions

View File

@@ -37,7 +37,8 @@ class DocumentMenu extends React.Component<Props> {
}; };
handleDuplicate = async (ev: SyntheticEvent<*>) => { handleDuplicate = async (ev: SyntheticEvent<*>) => {
this.props.document.duplicate(); const duped = await this.props.document.duplicate();
this.props.history.push(duped.url);
}; };
handlePin = (ev: SyntheticEvent<*>) => { handlePin = (ev: SyntheticEvent<*>) => {

View File

@@ -4,7 +4,6 @@ import invariant from 'invariant';
import { client } from 'utils/ApiClient'; import { client } from 'utils/ApiClient';
import stores from 'stores'; import stores from 'stores';
import UiStore from 'stores/UiStore';
import parseTitle from '../../shared/utils/parseTitle'; import parseTitle from '../../shared/utils/parseTitle';
import unescape from '../../shared/utils/unescape'; import unescape from '../../shared/utils/unescape';
@@ -17,7 +16,8 @@ type SaveOptions = { publish?: boolean, done?: boolean, autosave?: boolean };
class Document extends BaseModel { class Document extends BaseModel {
isSaving: boolean = false; isSaving: boolean = false;
hasPendingChanges: boolean = false; hasPendingChanges: boolean = false;
ui: UiStore; ui: *;
store: *;
collaborators: User[]; collaborators: User[];
collection: $Shape<Collection>; collection: $Shape<Collection>;
@@ -266,7 +266,7 @@ class Document extends BaseModel {
}; };
duplicate = () => { duplicate = () => {
this.emit('documents.duplicate', this); return this.store.duplicate(this);
}; };
download = async () => { download = async () => {
@@ -298,6 +298,7 @@ class Document extends BaseModel {
this.updateData(data); this.updateData(data);
this.ui = stores.ui; this.ui = stores.ui;
this.store = stores.documents;
} }
} }

View File

@@ -222,6 +222,7 @@ class DocumentsStore extends BaseStore {
id: duped.id, id: duped.id,
collectionId: duped.collection.id, collectionId: duped.collection.id,
}); });
return duped;
} }
}; };
@@ -257,9 +258,6 @@ class DocumentsStore extends BaseStore {
this.on('documents.create', (data: Document) => { this.on('documents.create', (data: Document) => {
this.add(data); this.add(data);
}); });
this.on('documents.duplicate', (data: Document) => {
this.duplicate(data);
});
// Re-fetch dashboard content so that we don't show deleted documents // Re-fetch dashboard content so that we don't show deleted documents
this.on('collections.delete', () => { this.on('collections.delete', () => {