From abfab4f1adb40e3463fa9e90aff3e92bfdf03693 Mon Sep 17 00:00:00 2001 From: Haishan Date: Fri, 26 Oct 2018 01:02:59 +0800 Subject: ui(proxy): new UI for proxy page --- src/components/ProxyGroup.js | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/components/ProxyGroup.js (limited to 'src/components/ProxyGroup.js') diff --git a/src/components/ProxyGroup.js b/src/components/ProxyGroup.js new file mode 100644 index 0000000..b697b27 --- /dev/null +++ b/src/components/ProxyGroup.js @@ -0,0 +1,80 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import memoize from 'memoize-one'; + +import Proxy from 'c/Proxy'; + +import s0 from './ProxyGroup.module.scss'; + +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import { getUserProxies, switchProxy } from 'd/proxies'; + +const mapStateToProps = s => { + return { + proxies: getUserProxies(s) + }; +}; + +const mapDispatchToProps = dispatch => { + return { + switchProxy: bindActionCreators(switchProxy, dispatch) + }; +}; + +// should move this to sth like constants.js +// const userProxyTypes = ['Shadowsocks', 'Vmess', 'Socks5']; + +class ProxyGroup extends Component { + static propTypes = { + // group name + name: PropTypes.string.isRequired, + proxies: PropTypes.object, + switchProxy: PropTypes.func + }; + + reOrderProxies = memoize((list, now) => { + const a = [now]; + list.forEach(i => i !== now && a.push(i)); + return a; + }); + + render() { + const { name, proxies, switchProxy } = this.props; + const group = proxies[name]; + let list; + if (group.all) { + list = this.reOrderProxies(group.all, group.now); + } else { + list = [group.now]; + } + return ( +
+
+

+ {name} + {group.type} +

+
+
+ {list.map(proxyName => { + return ( +
switchProxy(name, proxyName)} + > + +
+ ); + })} +
+
+ ); + } +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(ProxyGroup); -- cgit v1.3.1