mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
refactor(proxy): refactor props
This commit is contained in:
parent
510908c823
commit
0305a2c6ca
@ -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>
|
||||
)
|
||||
|
@ -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>
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user