mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-19 06:21: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 { to } from '@lib/helper'
|
||||||
import './style.scss'
|
import './style.scss'
|
||||||
|
|
||||||
interface ProxyProps extends BaseComponentProps, IProxy {}
|
interface ProxyProps extends BaseComponentProps {
|
||||||
|
config: IProxy
|
||||||
|
}
|
||||||
|
|
||||||
interface ProxyState {
|
interface ProxyState {
|
||||||
delay: number
|
delay: number
|
||||||
hasError: boolean
|
hasError: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Proxy extends React.Component<ProxyProps, ProxyState> {
|
export class Proxy extends React.Component<ProxyProps , ProxyState> {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
delay: -1,
|
delay: -1,
|
||||||
@ -20,8 +22,8 @@ export class Proxy extends React.Component<ProxyProps, ProxyState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount () {
|
async componentDidMount () {
|
||||||
const { name } = this.props
|
const { config } = this.props
|
||||||
const [res, err] = await to(getProxyDelay(name))
|
const [res, err] = await to(getProxyDelay(config.name))
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return this.setState({ hasError: true })
|
return this.setState({ hasError: true })
|
||||||
@ -32,12 +34,12 @@ export class Proxy extends React.Component<ProxyProps, ProxyState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { name, className } = this.props
|
const { config, className } = this.props
|
||||||
const { delay, hasError } = this.state
|
const { delay, hasError } = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classnames('proxy-item', { 'proxy-error': hasError }, className)}>
|
<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>
|
<span className="proxy-delay">{delay === -1 ? '-' : `${delay}s`}</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,7 @@ class Proxies extends React.Component<ProxiesProps, {}> {
|
|||||||
config.config.proxy.map(
|
config.config.proxy.map(
|
||||||
(p, index) => (
|
(p, index) => (
|
||||||
<li key={index}>
|
<li key={index}>
|
||||||
<Proxy name={p.name} config={p.config} />
|
<Proxy config={p} />
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user