Skip to content

Commit 7726654

Browse files
committed
Stop button
1 parent 6428289 commit 7726654

File tree

2 files changed

+67
-45
lines changed

2 files changed

+67
-45
lines changed

src/api/i18n.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ export const stringsToTranslate = [
485485
"Languages databases",
486486
"Last modified at",
487487
"left",
488+
"left for now",
488489
"Left text",
489490
"Legend",
490491
"Levenshtein distance limit for entity content matching",
@@ -609,6 +610,7 @@ export const stringsToTranslate = [
609610
"No filtered verbs",
610611
"No groups to select",
611612
"No header",
613+
"No input words or words to compare is received",
612614
"No instances",
613615
"No language degree of endangerment found",
614616
"No languages found",
@@ -617,6 +619,7 @@ export const stringsToTranslate = [
617619
"no prefix",
618620
"No results found.",
619621
"No settlement found",
622+
"No source perspective and/or perspective(s) for comparing is selected",
620623
"No statistics for the selected period",
621624
"No suggestions",
622625
"No translations.",
@@ -954,6 +957,7 @@ export const stringsToTranslate = [
954957
"Transliteration",
955958
"transpnition marker",
956959
"Transposition",
960+
"Truth threshold",
957961
"Try closing the dialog and opening it again; if the error persists, please contact administrators.",
958962
"Try reloading the page; if the error persists, please contact administrators.",
959963
"Type",

src/components/CognateAnalysisModal/index.js

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,14 +2404,14 @@ class CognateAnalysisModal extends React.Component {
24042404
xcriptFldId: info[2],
24052405
xlatFldId: info[3]
24062406
}
2407-
}).then(async ({ data: { words }}) => {
2407+
}).then(({ data: { words }}) => {
24082408

24092409
// We are going to get predictions for a group at once
24102410
// So we don't have to wait for all the process completion,
24112411
// and we don't have to initialize prediction model for every single word
24122412

24132413
const groups = [];
2414-
const group_size = 8;
2414+
const group_size = 4;
24152415

24162416
for (let i = 0; i < words.length; i += group_size) {
24172417
groups.push(words.slice(i, i + group_size));
@@ -2421,61 +2421,72 @@ class CognateAnalysisModal extends React.Component {
24212421
const total = groups.length;
24222422

24232423
// Initialize states for new process
2424-
this.setState({
2425-
computing: true,
2426-
result: null,
2427-
estimate: null,
2428-
suggestion_list: null,
2429-
sg_select_list: null,
2430-
sg_state_list: null,
2431-
sg_count: null,
2432-
sg_entry_map: null,
2433-
dictionary_count: 0,
2434-
transcription_count: 0,
2435-
total
2436-
});
2424+
this.setState(
2425+
{
2426+
computing: true,
2427+
result: null,
2428+
estimate: null,
2429+
suggestion_list: null,
2430+
sg_select_list: null,
2431+
sg_state_list: null,
2432+
sg_count: null,
2433+
sg_entry_map: null,
2434+
dictionary_count: 0,
2435+
transcription_count: 0,
2436+
total
2437+
},
2438+
// Running after setstate
2439+
async () => {
2440+
for (const [done, pairs] of groups.entries()) {
2441+
this.setState({ done });
2442+
2443+
const { data, error } = await computeNeuroCognateAnalysis({
2444+
variables: {
2445+
inputPairs: pairs,
2446+
matchTranslations: this.state.matchTranslationsFlag,
2447+
sourcePerspectiveId: perspectiveId,
2448+
baseLanguageId: this.baseLanguageId,
2449+
truthThreshold: this.state.truthThreshold,
2450+
perspectiveInfoList
2451+
}
2452+
});
24372453

2438-
for (const [done, pairs] of groups.entries()) {
2439-
this.setState({ done });
2440-
2441-
const { data, error } = await computeNeuroCognateAnalysis({
2442-
variables: {
2443-
inputPairs: pairs,
2444-
matchTranslations: this.state.matchTranslationsFlag,
2445-
sourcePerspectiveId: perspectiveId,
2446-
baseLanguageId: this.baseLanguageId,
2447-
truthThreshold: this.state.truthThreshold,
2448-
perspectiveInfoList
2449-
}
2450-
});
2454+
// On Stop button click
2455+
if (!this.state.computing) {
2456+
return;
2457+
}
24512458

2452-
if (error) {
2453-
this.handleError(error);
2454-
return;
2455-
}
2459+
if (error) {
2460+
this.handleError(error);
2461+
return;
2462+
}
24562463

2457-
if (!this.handleNeuroResult(data)) {
2458-
this.setState({ computing: false });
2459-
return;
2460-
}
2464+
// If any troubles in response
2465+
if (!this.handleNeuroResult(data)) {
2466+
this.setState({ computing: false });
2467+
return;
2468+
}
24612469

2462-
const duration = (Date.now() - start) / 1000;
2463-
const estimate = duration / (done + 1) * total - duration;
2464-
const days = Math.trunc(estimate / 86400);
2465-
const hours = Math.trunc((estimate - days * 86400) / 3600);
2466-
const minutes = Math.round((estimate - days * 86400 - hours * 3600) / 60);
2470+
const duration = (Date.now() - start) / 1000;
2471+
const estimate = duration / (done + 1) * total - duration;
2472+
const days = Math.trunc(estimate / 86400);
2473+
const hours = Math.trunc((estimate - days * 86400) / 3600);
2474+
const minutes = Math.round((estimate - days * 86400 - hours * 3600) / 60);
24672475

2468-
this.setState({ estimate: `${days}d:${hours}h:${minutes}m` });
2469-
}
2476+
this.setState({ estimate: `${days}d:${hours}h:${minutes}m` });
2477+
}
2478+
2479+
this.setState({ computing: false });
2480+
}
2481+
);
24702482
});
24712483

24722484
} else {
24732485

24742486
window.logger.err(this.context("No source perspective and/or perspective(s) for comparing is selected"));
2487+
this.setState({ computing: false });
24752488
}
24762489

2477-
this.setState({ computing: false });
2478-
24792490
} else {
24802491

24812492
/* Otherwise we will launch it as usual and then will wait for results to display them. */
@@ -3202,6 +3213,13 @@ class CognateAnalysisModal extends React.Component {
32023213
{ lang_mode === "none" ? this.browse_files_render() : this.language_render(lang_mode === "multi") }
32033214

32043215
<Modal.Actions>
3216+
{ (mode === "neuro_suggestions" || mode === "multi_neuro_suggestions") && computing && (
3217+
<Button
3218+
content={this.context("Stop")}
3219+
onClick={() => this.setState({ computing: false })}
3220+
className="lingvo-button-red"
3221+
/>
3222+
)}
32053223
<Button
32063224
content={
32073225
computing ? (

0 commit comments

Comments
 (0)