Add logs to popup page

This commit is contained in:
sienori 2019-08-22 14:48:14 +09:00
parent b9c68179e4
commit 66647f69f6

View file

@ -1,5 +1,6 @@
import React, { Component } from "react"; import React, { Component } from "react";
import browser from "webextension-polyfill"; import browser from "webextension-polyfill";
import log from "loglevel";
import { initSettings, getSettings } from "src/settings/settings"; import { initSettings, getSettings } from "src/settings/settings";
import { updateLogLevel, overWriteLogLevel } from "src/common/log"; import { updateLogLevel, overWriteLogLevel } from "src/common/log";
import translate from "src/common/translate"; import translate from "src/common/translate";
@ -9,6 +10,8 @@ import ResultArea from "./ResultArea";
import Footer from "./Footer"; import Footer from "./Footer";
import "../styles/PopupPage.scss"; import "../styles/PopupPage.scss";
const logDir = "popup/PopupPage";
const getTabInfo = async () => { const getTabInfo = async () => {
try { try {
const tab = (await browser.tabs.query({ currentWindow: true, active: true }))[0]; const tab = (await browser.tabs.query({ currentWindow: true, active: true }))[0];
@ -64,6 +67,7 @@ export default class PopupPage extends Component {
}; };
handleInputText = inputText => { handleInputText = inputText => {
log.log(logDir, "handleInputText()", inputText);
this.setState({ inputText: inputText }); this.setState({ inputText: inputText });
const waitTime = getSettings("waitTime"); const waitTime = getSettings("waitTime");
@ -75,12 +79,14 @@ export default class PopupPage extends Component {
}; };
handleLangChange = lang => { handleLangChange = lang => {
log.info(logDir, "handleLangChange()", lang);
this.setState({ targetLang: lang }); this.setState({ targetLang: lang });
const inputText = this.state.inputText; const inputText = this.state.inputText;
if (inputText !== "") this.translateText(inputText, lang); if (inputText !== "") this.translateText(inputText, lang);
}; };
translateText = async (text, targetLang) => { translateText = async (text, targetLang) => {
log.info(logDir, "translateText()", text, targetLang);
const result = await translate(text, "auto", targetLang); const result = await translate(text, "auto", targetLang);
this.setState({ this.setState({
resultText: result.resultText, resultText: result.resultText,
@ -104,11 +110,13 @@ export default class PopupPage extends Component {
if (!this.isSwitchedSecondLang) { if (!this.isSwitchedSecondLang) {
if (equalsSourceAndTarget && equalsSourceAndDefault) { if (equalsSourceAndTarget && equalsSourceAndDefault) {
log.info(logDir, "=>switchSecondLang()", result, secondLang);
this.handleLangChange(secondLang); this.handleLangChange(secondLang);
this.isSwitchedSecondLang = true; this.isSwitchedSecondLang = true;
} }
} else { } else {
if (!equalsSourceAndDefault) { if (!equalsSourceAndDefault) {
log.info(logDir, "=>switchSecondLang()", result, defaultTargetLang);
this.handleLangChange(defaultTargetLang); this.handleLangChange(defaultTargetLang);
this.isSwitchedSecondLang = false; this.isSwitchedSecondLang = false;
} }