2023-09-02 12:34:23 +08:00
|
|
|
import { createMemo } from 'solid-js'
|
2023-09-02 12:05:31 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
|
|
|
import Delay from '~/components/Delay'
|
|
|
|
import { DELAY } from '~/config/enum'
|
|
|
|
import { useProxies } from '~/signals/proxies'
|
|
|
|
|
|
|
|
export default (props: { proxyNameList: string[]; now?: string }) => {
|
|
|
|
const { proxyNodeMap } = useProxies()
|
2023-09-02 12:34:23 +08:00
|
|
|
const delayList = createMemo(() =>
|
|
|
|
props.proxyNameList.map((i) => proxyNodeMap()[i].delay!),
|
|
|
|
)
|
|
|
|
const all = createMemo(() => delayList().length)
|
|
|
|
const good = createMemo(
|
|
|
|
() =>
|
|
|
|
delayList().filter(
|
|
|
|
(delay) => delay > DELAY.NOT_CONNECTED && delay <= DELAY.MEDIUM,
|
|
|
|
).length,
|
|
|
|
)
|
|
|
|
const middle = createMemo(
|
|
|
|
() =>
|
|
|
|
delayList().filter((delay) => delay > DELAY.MEDIUM && delay <= DELAY.HIGH)
|
|
|
|
.length,
|
|
|
|
)
|
|
|
|
const slow = createMemo(
|
|
|
|
() => delayList().filter((delay) => delay > DELAY.HIGH).length,
|
|
|
|
)
|
|
|
|
const notConnected = createMemo(
|
|
|
|
() =>
|
|
|
|
delayList().filter(
|
|
|
|
(delay) => delay === DELAY.NOT_CONNECTED || typeof delay !== 'number',
|
|
|
|
).length,
|
|
|
|
)
|
|
|
|
|
2023-09-02 12:05:31 +08:00
|
|
|
return (
|
|
|
|
<div class="flex w-full items-center">
|
|
|
|
<div class="flex flex-1 overflow-hidden rounded-2xl">
|
|
|
|
<div
|
|
|
|
class={twMerge('h-2 bg-success')}
|
|
|
|
style={{
|
2023-09-02 12:34:23 +08:00
|
|
|
width: `${(good() * 100) / all()}%`, // cant use tw class cause dynamic classname wont import
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
class={twMerge('h-2 bg-warning')}
|
|
|
|
style={{
|
2023-09-02 12:34:23 +08:00
|
|
|
width: `${(middle() * 100) / all()}%`,
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
class={twMerge('h-2 bg-error')}
|
|
|
|
style={{
|
2023-09-02 12:34:23 +08:00
|
|
|
width: `${(slow() * 100) / all()}%`,
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
class={twMerge('h-2 bg-neutral')}
|
|
|
|
style={{
|
2023-09-02 12:34:23 +08:00
|
|
|
width: `${(notConnected() * 100) / all()}%`,
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
</div>
|
2023-09-02 12:34:23 +08:00
|
|
|
<div class="ml-3 w-8 text-xs">
|
|
|
|
<Delay name={props.now} />
|
2023-09-02 12:05:31 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|