Tweaks for seamless save of new doc

This commit is contained in:
Tom Moor
2017-12-28 12:35:59 +00:00
parent 721374e08d
commit 2d70618f01
3 changed files with 63 additions and 63 deletions

View File

@@ -190,9 +190,10 @@ class Document extends BaseModel {
data.parentDocument = this.parentDocument;
}
res = await client.post('/documents.create', data);
invariant(res && res.data, 'Data should be available');
this.emit('documents.create', res.data);
}
runInAction('Document#save', () => {
invariant(res && res.data, 'Data should be available');
this.updateData(res.data);
this.hasPendingChanges = false;
});

View File

@@ -211,7 +211,6 @@ class DocumentScene extends Component {
const isNew = this.props.newDocument;
const isMoving = this.props.match.path === matchDocumentMove;
const document = this.document;
const isFetching = !document;
const titleText =
get(document, 'title', '') ||
this.props.collections.titleForDocument(this.props.location.pathname);
@@ -226,13 +225,11 @@ class DocumentScene extends Component {
{isMoving && document && <DocumentMove document={document} />}
{titleText && <PageTitle title={titleText} />}
{(this.isLoading || this.isSaving) && <LoadingIndicator />}
{isFetching && (
{!document ? (
<CenteredContent>
<LoadingState />
</CenteredContent>
)}
{!isFetching &&
document && (
) : (
<Flex justify="center" auto>
{this.isEditing && (
<Prompt
@@ -241,7 +238,6 @@ class DocumentScene extends Component {
/>
)}
<Editor
key={`${document.id}-${document.revision}`}
text={document.text}
emoji={document.emoji}
onImageUploadStart={this.onImageUploadStart}

View File

@@ -203,6 +203,9 @@ class DocumentsStore extends BaseStore {
this.on('documents.delete', (data: { id: string }) => {
this.remove(data.id);
});
this.on('documents.create', (data: Document) => {
this.add(new Document(data));
});
autorunAsync('DocumentsStore.persists', () => {
if (this.data.size) {