Added edit cache for canceling edit changes
This commit is contained in:
@@ -41,6 +41,7 @@ type Props = {
|
|||||||
props: Props;
|
props: Props;
|
||||||
savedTimeout: number;
|
savedTimeout: number;
|
||||||
|
|
||||||
|
@observable editCache: ?string;
|
||||||
@observable newDocument: ?Document;
|
@observable newDocument: ?Document;
|
||||||
@observable isDragging = false;
|
@observable isDragging = false;
|
||||||
@observable isLoading = false;
|
@observable isLoading = false;
|
||||||
@@ -86,6 +87,8 @@ type Props = {
|
|||||||
|
|
||||||
if (document) {
|
if (document) {
|
||||||
this.props.ui.setActiveDocument(document);
|
this.props.ui.setActiveDocument(document);
|
||||||
|
// Cache data if user enters edit mode and cancels
|
||||||
|
this.editCache = document.text;
|
||||||
document.view();
|
document.view();
|
||||||
} else {
|
} else {
|
||||||
// Render 404 with search
|
// Render 404 with search
|
||||||
@@ -104,6 +107,7 @@ type Props = {
|
|||||||
onClickEdit = () => {
|
onClickEdit = () => {
|
||||||
if (!this.document) return;
|
if (!this.document) return;
|
||||||
const url = `${this.document.url}/edit`;
|
const url = `${this.document.url}/edit`;
|
||||||
|
this.editCache = document.text;
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -152,7 +156,7 @@ type Props = {
|
|||||||
let url;
|
let url;
|
||||||
if (this.document && this.document.url) {
|
if (this.document && this.document.url) {
|
||||||
url = this.document.url;
|
url = this.document.url;
|
||||||
await this.document.fetch();
|
if (this.editCache) this.document.updateData({ text: this.editCache });
|
||||||
} else {
|
} else {
|
||||||
url = collectionUrl(this.props.match.params.id);
|
url = collectionUrl(this.props.match.params.id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user