2023-09-02 12:34:23 +08:00
|
|
|
import { createMemo } from 'solid-js'
|
2023-09-03 03:56:04 +08:00
|
|
|
import { Latency } from '~/components'
|
|
|
|
import { latencyQualityMap, useProxies } from '~/signals'
|
2023-09-02 12:05:31 +08:00
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const ProxyPreviewBar = (props: {
|
|
|
|
proxyNameList: string[]
|
|
|
|
now?: string
|
|
|
|
}) => {
|
2023-09-02 15:00:13 +08:00
|
|
|
const { delayMap } = useProxies()
|
2023-09-02 12:34:23 +08:00
|
|
|
const delayList = createMemo(() =>
|
2023-09-02 15:00:13 +08:00
|
|
|
props.proxyNameList.map((i) => delayMap()[i]),
|
2023-09-02 12:34:23 +08:00
|
|
|
)
|
|
|
|
const all = createMemo(() => delayList().length)
|
|
|
|
const good = createMemo(
|
|
|
|
() =>
|
|
|
|
delayList().filter(
|
2023-09-03 03:56:04 +08:00
|
|
|
(delay) =>
|
|
|
|
delay > latencyQualityMap().NOT_CONNECTED &&
|
|
|
|
delay <= latencyQualityMap().MEDIUM,
|
2023-09-02 12:34:23 +08:00
|
|
|
).length,
|
|
|
|
)
|
|
|
|
const middle = createMemo(
|
|
|
|
() =>
|
2023-09-03 03:56:04 +08:00
|
|
|
delayList().filter(
|
|
|
|
(delay) =>
|
|
|
|
delay > latencyQualityMap().NOT_CONNECTED &&
|
|
|
|
delay <= latencyQualityMap().HIGH,
|
|
|
|
).length,
|
2023-09-02 12:34:23 +08:00
|
|
|
)
|
|
|
|
const slow = createMemo(
|
2023-09-03 03:56:04 +08:00
|
|
|
() =>
|
|
|
|
delayList().filter((delay) => delay > latencyQualityMap().HIGH).length,
|
2023-09-02 12:34:23 +08:00
|
|
|
)
|
|
|
|
const notConnected = createMemo(
|
|
|
|
() =>
|
|
|
|
delayList().filter(
|
2023-09-03 03:56:04 +08:00
|
|
|
(delay) =>
|
|
|
|
delay === latencyQualityMap().NOT_CONNECTED ||
|
|
|
|
typeof delay !== 'number',
|
2023-09-02 12:34:23 +08:00
|
|
|
).length,
|
|
|
|
)
|
|
|
|
|
2023-09-02 12:05:31 +08:00
|
|
|
return (
|
2023-09-02 14:25:22 +08:00
|
|
|
<div class="flex h-6 w-full items-center">
|
2023-09-02 12:05:31 +08:00
|
|
|
<div class="flex flex-1 overflow-hidden rounded-2xl">
|
|
|
|
<div
|
2023-09-02 14:25:22 +08:00
|
|
|
class="h-2 bg-success"
|
2023-09-02 12:05:31 +08:00
|
|
|
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
|
2023-09-02 14:25:22 +08:00
|
|
|
class="h-2 bg-warning"
|
2023-09-02 12:05:31 +08:00
|
|
|
style={{
|
2023-09-02 12:34:23 +08:00
|
|
|
width: `${(middle() * 100) / all()}%`,
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<div
|
2023-09-02 14:25:22 +08:00
|
|
|
class="h-2 bg-error"
|
2023-09-02 12:05:31 +08:00
|
|
|
style={{
|
2023-09-02 12:34:23 +08:00
|
|
|
width: `${(slow() * 100) / all()}%`,
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<div
|
2023-09-02 14:25:22 +08:00
|
|
|
class="h-2 bg-neutral"
|
2023-09-02 12:05:31 +08:00
|
|
|
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">
|
2023-09-03 03:56:04 +08:00
|
|
|
<Latency name={props.now} />
|
2023-09-02 12:05:31 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|