Add request timeout to corrections

parent 466bf059
......@@ -14,7 +14,8 @@ class App extends Component {
super(props, context);
this.state = {
correctionMode: false
correctionMode: false,
isTimeout: false,
}
this.typo = "";
......@@ -33,6 +34,11 @@ class App extends Component {
registerHandlers() {
$(document).keydown(event => {
if (event.ctrlKey && event.keyCode === 13) {
if (this.state.isTimeout) {
alertify.error(i18n.errorTooOften);
return;
}
const selection = this.getSelectedText();
if (selection === "") {
......@@ -71,8 +77,15 @@ class App extends Component {
// This method is invoked when a modal has been closed
modalClosedCallback = () => {
this.setState({
correctionMode: false
})
correctionMode: false,
isTimeout: true,
});
window.setTimeout(() => {
console.log("state", this.state);
this.setState({ isTimeout: false });
console.log("afterstate", this.state);
}, config.requestTimeout);
}
}
......
......@@ -13,6 +13,7 @@ export const i18n = new LocalizedStrings({
errorSelectionLength: "Опечатка должна быть длиной от {0} до {1} символов",
errorCorrectLength: "Исправление должно быть длиной от {0} до {1} символов",
errorDoesNotDistinct: "Исправленный вариант идентичен исходному",
errorTooOften: "Вы отправляете исправления слишком часто",
close: "Закрыть",
saveChanges: "Сохранить изменения",
messageSuccess: "Благодарим за отправку. Опечатка будет исправлена",
......
......@@ -18,7 +18,7 @@ class TypoModal extends Component {
text: this.props.text,
correct: this.props.text,
comment: "",
error: "",
error: ""
}
this.closeCallback = props.closeCallback;
......@@ -71,13 +71,16 @@ class TypoModal extends Component {
// Send typo to the typos server
submitTypo = (corrected, comment) => {
if (this.checkData()) {
this.handleClose();
alertify.success(i18n.messageSuccess);
if (!this.checkData()) {
alertify.error(i18n.messageFailture);
return;
}
alertify.error(i18n.messageFailture)
this.handleClose();
alertify.success(i18n.messageSuccess);
return;
}
render() {
......
......@@ -3,4 +3,7 @@ export const config = {
minTypoLength: 4,
maxCorrectLength: 100,
minCorrectLength: 1,
serverUrl: "//eterfund.ru/api/typos/server.php",
requestTimeout: 10000,
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment