From c162de041d6b082f6c9157c639ff21d90f632ebd Mon Sep 17 00:00:00 2001 From: sienori Date: Fri, 1 May 2020 23:35:48 +0900 Subject: [PATCH] Add listen button --- src/_locales/en/messages.json | 3 +++ src/popup/components/CopyButton.js | 38 ++++++++++++++++++++++++++ src/popup/components/InputArea.js | 11 ++++++-- src/popup/components/ListenButton.js | 32 ++++++++++++++++++++++ src/popup/components/MediaButtons.js | 40 ---------------------------- src/popup/components/PopupPage.js | 10 +++++-- src/popup/components/ResultArea.js | 10 ++++--- src/popup/icons/speaker.svg | 3 +++ src/popup/styles/CopyButton.scss | 27 +++++++++++++++++++ src/popup/styles/InputArea.scss | 9 +++++++ src/popup/styles/ListenButton.scss | 15 +++++++++++ src/popup/styles/MediaButtons.scss | 33 ----------------------- src/popup/styles/ResultArea.scss | 12 ++++++++- 13 files changed, 162 insertions(+), 81 deletions(-) create mode 100644 src/popup/components/CopyButton.js create mode 100644 src/popup/components/ListenButton.js delete mode 100644 src/popup/components/MediaButtons.js create mode 100644 src/popup/icons/speaker.svg create mode 100644 src/popup/styles/CopyButton.scss create mode 100644 src/popup/styles/ListenButton.scss delete mode 100644 src/popup/styles/MediaButtons.scss diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index c65165a..f8e2ecd 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -33,6 +33,9 @@ "copiedLabel": { "message": "Copied." }, + "listenLabel": { + "message": "Listen" + }, "targetLangLabel": { "message": "Target language" }, diff --git a/src/popup/components/CopyButton.js b/src/popup/components/CopyButton.js new file mode 100644 index 0000000..01b470e --- /dev/null +++ b/src/popup/components/CopyButton.js @@ -0,0 +1,38 @@ +import React, { Component } from "react"; +import browser from "webextension-polyfill"; +import { CopyToClipboard } from "react-copy-to-clipboard"; +import CopyIcon from "../icons/copy.svg"; +import "../styles/CopyButton.scss"; + +export default class CopyButton extends Component { + constructor(props) { + super(props); + this.state = { isCopied: false }; + } + + handleCopy = () => { + this.setState({ isCopied: true }); + }; + + componentWillReceiveProps(nextProps) { + if (this.props.text !== nextProps.text) this.setState({ isCopied: false }); + } + + render() { + const { text } = this.props; + if (!text) return null; + + return ( +
+ {this.state.isCopied && ( + {browser.i18n.getMessage("copiedLabel")} + )} + + + +
+ ); + } +} diff --git a/src/popup/components/InputArea.js b/src/popup/components/InputArea.js index b97ab06..75f6f3f 100644 --- a/src/popup/components/InputArea.js +++ b/src/popup/components/InputArea.js @@ -1,6 +1,7 @@ import React, { Component } from "react"; import ReactDOM from "react-dom"; import browser from "webextension-polyfill"; +import ListenButton from "./ListenButton"; import "../styles/inputArea.scss"; export default class InputArea extends Component { @@ -16,7 +17,9 @@ export default class InputArea extends Component { }; shouldComponentUpdate(nextProps) { - const shouldUpdate = this.props.inputText !== nextProps.inputText; + const shouldUpdate = + this.props.inputText !== nextProps.inputText || + this.props.sourceLang !== nextProps.sourceLang; return shouldUpdate; } @@ -25,16 +28,20 @@ export default class InputArea extends Component { }; render() { + const { inputText, sourceLang } = this.props; return (