From 0d15987b6621ebbcd34f82287f61ca82833f7373 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Fri, 29 Dec 2017 23:10:25 +0300 Subject: [PATCH] refactor coin tile actions as menu --- .../dashboard/coinTile/coinTileItem.js | 63 ++++++++++++++++--- .../dashboard/coinTile/coinTileItem.render.js | 32 ++++++++-- .../walletsTxInfo/walletsTxInfo.render.js | 2 + react/src/components/overrides.scss | 18 +++++- 4 files changed, 100 insertions(+), 15 deletions(-) diff --git a/react/src/components/dashboard/coinTile/coinTileItem.js b/react/src/components/dashboard/coinTile/coinTileItem.js index 0031f28..8acb29f 100644 --- a/react/src/components/dashboard/coinTile/coinTileItem.js +++ b/react/src/components/dashboard/coinTile/coinTileItem.js @@ -46,8 +46,55 @@ class CoinTileItem extends React.Component { activeCoin: null, activeCoinMode: null, propsUpdatedCounter: 0, + toggledCoinMenu: null, }; this.autoSetActiveCoin = this.autoSetActiveCoin.bind(this); + this.toggleCoinMenu = this.toggleCoinMenu.bind(this); + this.handleClickOutside = this.handleClickOutside.bind(this); + } + + componentWillMount() { + const appConfig = mainWindow.appConfig; + + if (!this.props.ActiveCoin.coin) { + this.autoSetActiveCoin(); + } + + this.setState({ + appConfig, + }); + + document.addEventListener( + 'click', + this.handleClickOutside, + false + ); + } + + componentWillUnmount() { + document.removeEventListener( + 'click', + this.handleClickOutside, + false + ); + } + + handleClickOutside(e) { + if (e && + e.srcElement && + e.srcElement.offsetParent && + e.srcElement.offsetParent.className.indexOf('dropdown') === -1 && + (e.srcElement.offsetParent && e.srcElement.offsetParent.className.indexOf('dropdown') === -1)) { + this.setState({ + toggledCoinMenu: e.srcElement.className.indexOf('coin-tile-context-menu-trigger') === -1 ? null : this.state.toggledCoinMenu, + }); + } + } + + toggleCoinMenu(coin) { + this.setState({ + toggledCoinMenu: this.state.toggledCoinMenu === coin ? null : coin, + }); } openCoindDownModal() { @@ -130,19 +177,11 @@ class CoinTileItem extends React.Component { } } - componentWillMount() { - if (!this.props.ActiveCoin.coin) { - this.autoSetActiveCoin(); - } - - const appConfig = mainWindow.appConfig; - + removeCoin(coin, mode) { this.setState({ - appConfig, + toggledCoinMenu: null, }); - } - removeCoin(coin, mode) { shepherdRemoveCoin(coin, mode) .then((res) => { Store.dispatch( @@ -163,6 +202,10 @@ class CoinTileItem extends React.Component { } stopCoind(coin) { + this.setState({ + toggledCoinMenu: null, + }); + shepherdStopCoind(coin) .then((res) => { if (res.msg === 'error') { diff --git a/react/src/components/dashboard/coinTile/coinTileItem.render.js b/react/src/components/dashboard/coinTile/coinTileItem.render.js index e281b1d..2028a83 100644 --- a/react/src/components/dashboard/coinTile/coinTileItem.render.js +++ b/react/src/components/dashboard/coinTile/coinTileItem.render.js @@ -24,17 +24,41 @@ const CoinTileItemRender = function() { - { this.renderStopCoinButton() && + + { this.state.toggledCoinMenu && + this.state.toggledCoinMenu === item.coin && +
+ +
+ } + { /*this.renderStopCoinButton() && this.stopCoind(item.coin, item.mode) } title={ translate('DASHBOARD.STOP') } - className="icon fa-stop-circle coind-stop-icon"> + className="icon fa-stop-circle coind-stop-icon">*/ } - { this.renderRemoveCoinButton() && + { /*this.renderRemoveCoinButton() && this.removeCoin(item.coin, item.mode) } title={ translate('DASHBOARD.REMOVE') } - className={ 'icon fa-plus-circle coind-remove-icon' + (item.mode === 'spv' ? ' coind-remove-icon-spv' : '') }> + className={ 'icon fa-plus-circle coind-remove-icon' + (item.mode === 'spv' ? ' coind-remove-icon-spv' : '') }>*/ } { this.props.Dashboard && this.props.Dashboard.electrumCoins && diff --git a/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js b/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js index ad4e50e..c46f8a0 100644 --- a/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js +++ b/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js @@ -2,6 +2,7 @@ import React from 'react'; import { translate } from '../../../translate/translate'; import { secondsToString } from '../../../util/time'; import Config from '../../../config'; +import { isKomodoCoin } from '../../../util/coinHelper'; const WalletsTxInfoRender = function(txInfo) { return ( @@ -190,6 +191,7 @@ const WalletsTxInfoRender = function(txInfo) {
{ this.state.txDetails && this.props.ActiveCoin.coin !== 'CHIPS' && + isKomodoCoin(this.props.ActiveCoin.coin) &&