Fix infinite loop when switching to second language

This commit is contained in:
sienori 2019-08-22 14:37:41 +09:00
parent 2ea456aa82
commit b9c68179e4

View file

@ -60,7 +60,7 @@ export default class PopupPage extends Component {
tabUrl: tabInfo.url, tabUrl: tabInfo.url,
isEnabledOnPage: tabInfo.isEnabledOnPage isEnabledOnPage: tabInfo.isEnabledOnPage
}); });
if (tabInfo.selectedText !== "") this.translateText(tabInfo.selectedText, targetLang); if (tabInfo.selectedText !== "") this.handleInputText(tabInfo.selectedText);
}; };
handleInputText = inputText => { handleInputText = inputText => {
@ -68,10 +68,10 @@ export default class PopupPage extends Component {
const waitTime = getSettings("waitTime"); const waitTime = getSettings("waitTime");
clearTimeout(this.inputTimer); clearTimeout(this.inputTimer);
this.inputTimer = setTimeout( this.inputTimer = setTimeout(async () => {
() => this.translateText(inputText, this.state.targetLang), const result = await this.translateText(inputText, this.state.targetLang);
waitTime this.switchSecondLang(result);
); }, waitTime);
}; };
handleLangChange = lang => { handleLangChange = lang => {
@ -87,7 +87,7 @@ export default class PopupPage extends Component {
candidateText: result.candidateText, candidateText: result.candidateText,
statusText: result.statusText statusText: result.statusText
}); });
this.switchSecondLang(result); return result;
}; };
switchSecondLang = result => { switchSecondLang = result => {