save document at enter press in name input

Signed-off-by: Stepan Usatyuk <usaatyuk@ustk.me>
This commit is contained in:
2019-05-01 00:12:13 +03:00
parent b49ec2f07e
commit 66abd85149
2 changed files with 52 additions and 27 deletions

View File

@@ -4098,12 +4098,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@@ -4118,17 +4120,20 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@@ -4245,7 +4250,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@@ -4257,6 +4263,7 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@@ -4271,6 +4278,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@@ -4278,12 +4286,14 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@@ -4302,6 +4312,7 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@@ -4382,7 +4393,8 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@@ -4394,6 +4406,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@@ -4515,6 +4528,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",

View File

@@ -63,6 +63,9 @@ export class DocumentEditComponent extends React.PureComponent<
this.state = defaultDocumentEditComponentState; this.state = defaultDocumentEditComponentState;
this.handleInputChange = this.handleInputChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this);
this.handleNameKeyPress = this.handleNameKeyPress.bind(this);
this.remove = this.remove.bind(this);
this.save = this.save.bind(this);
this.onUnload = this.onUnload.bind(this); this.onUnload = this.onUnload.bind(this);
} }
@@ -76,37 +79,20 @@ export class DocumentEditComponent extends React.PureComponent<
onChange={this.handleInputChange} onChange={this.handleInputChange}
name="name" name="name"
value={this.state.name} value={this.state.name}
onKeyPress={this.handleNameKeyPress}
/> />
<div className="buttons"> <div className="buttons">
<Button <Button
icon="trash" icon="trash"
minimal={true} minimal={true}
intent="danger" intent="danger"
onClick={() => { onClick={this.remove}
this.props.history.push(`/`);
this.props.deleteDoc(this.state.id);
AppToaster.show({
message: "Document deleted!",
intent: "danger",
timeout: 2900,
action: {
text: "Undo",
onClick: () =>
this.props.cancelDelete(),
},
});
}}
/> />
<Button <Button
icon="tick" icon="tick"
intent="success" intent="success"
minimal={true} minimal={true}
onClick={() => { onClick={this.save}
this.update();
this.props.history.push(
`/docs/${this.state.id}`,
);
}}
/> />
</div> </div>
</div> </div>
@@ -135,6 +121,31 @@ export class DocumentEditComponent extends React.PureComponent<
} as any); } as any);
} }
public remove() {
this.props.history.push(`/`);
this.props.deleteDoc(this.state.id);
AppToaster.show({
message: "Document deleted!",
intent: "danger",
timeout: 2900,
action: {
text: "Undo",
onClick: () => this.props.cancelDelete(),
},
});
}
public save() {
this.update();
this.props.history.push(`/docs/${this.state.id}`);
}
public handleNameKeyPress(event: React.KeyboardEvent<HTMLInputElement>) {
if (event.key === "Enter") {
this.save();
}
}
public handleInputChange( public handleInputChange(
event: event:
| React.FormEvent<HTMLInputElement> | React.FormEvent<HTMLInputElement>