2023-09-02 12:34:23 +08:00
|
|
|
import { Show, createEffect, createMemo, createSignal } from 'solid-js'
|
2023-09-02 11:52:51 +08:00
|
|
|
import { DELAY } from '~/config/enum'
|
2023-09-02 12:34:23 +08:00
|
|
|
import { useProxies } from '~/signals/proxies'
|
2023-09-02 11:52:51 +08:00
|
|
|
|
2023-09-02 12:34:23 +08:00
|
|
|
const Delay = (props: { name?: string }) => {
|
|
|
|
const { proxyNodeMap } = useProxies()
|
|
|
|
const [textClassName, setTextClassName] = createSignal('')
|
|
|
|
const delay = createMemo(() => {
|
|
|
|
return proxyNodeMap()[props.name!]?.delay!
|
|
|
|
})
|
2023-09-02 11:52:51 +08:00
|
|
|
|
2023-09-02 12:34:23 +08:00
|
|
|
createEffect(() => {
|
|
|
|
setTextClassName('text-success')
|
2023-09-02 11:52:51 +08:00
|
|
|
|
2023-09-02 12:34:23 +08:00
|
|
|
if (delay() > DELAY.HIGH) {
|
|
|
|
setTextClassName('text-error')
|
|
|
|
} else if (delay() > DELAY.MEDIUM) {
|
|
|
|
setTextClassName('text-warning')
|
|
|
|
}
|
|
|
|
})
|
2023-09-02 11:52:51 +08:00
|
|
|
|
2023-09-02 12:34:23 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Show
|
|
|
|
when={typeof delay() === 'number' && delay() !== DELAY.NOT_CONNECTED}
|
|
|
|
>
|
|
|
|
<span class={textClassName()}>{delay()}ms</span>
|
|
|
|
</Show>
|
|
|
|
</>
|
|
|
|
)
|
2023-09-02 11:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Delay
|