refactor(proxy): refactor props

This commit is contained in:
chs97 2018-10-25 23:11:51 +08:00
parent 510908c823
commit 0305a2c6ca
2 changed files with 9 additions and 7 deletions

View File

@ -5,14 +5,16 @@ import { getProxyDelay } from '@lib/request'
import { to } from '@lib/helper'
import './style.scss'
interface ProxyProps extends BaseComponentProps, IProxy {}
interface ProxyProps extends BaseComponentProps {
config: IProxy
}
interface ProxyState {
delay: number
hasError: boolean
}
export class Proxy extends React.Component<ProxyProps, ProxyState> {
export class Proxy extends React.Component<ProxyProps , ProxyState> {
state = {
delay: -1,
@ -20,8 +22,8 @@ export class Proxy extends React.Component<ProxyProps, ProxyState> {
}
async componentDidMount () {
const { name } = this.props
const [res, err] = await to(getProxyDelay(name))
const { config } = this.props
const [res, err] = await to(getProxyDelay(config.name))
if (err) {
return this.setState({ hasError: true })
@ -32,12 +34,12 @@ export class Proxy extends React.Component<ProxyProps, ProxyState> {
}
render () {
const { name, className } = this.props
const { config, className } = this.props
const { delay, hasError } = this.state
return (
<div className={classnames('proxy-item', { 'proxy-error': hasError }, className)}>
<span className="proxy-name">{name}</span>
<span className="proxy-name">{config.name}</span>
<span className="proxy-delay">{delay === -1 ? '-' : `${delay}s`}</span>
</div>
)

View File

@ -33,7 +33,7 @@ class Proxies extends React.Component<ProxiesProps, {}> {
config.config.proxy.map(
(p, index) => (
<li key={index}>
<Proxy name={p.name} config={p.config} />
<Proxy config={p} />
</li>
)
)