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-03 05:35:08 +08:00
|
|
|
const { latencyMap } = useProxies()
|
2023-09-03 05:40:39 +08:00
|
|
|
const latencyList = createMemo(() =>
|
2023-09-03 06:08:53 +08:00
|
|
|
props.proxyNameList.map((name) => latencyMap()[name]),
|
2023-09-02 12:34:23 +08:00
|
|
|
)
|
2023-09-04 01:12:29 +08:00
|
|
|
|
2023-09-03 05:40:39 +08:00
|
|
|
const all = createMemo(() => latencyList().length)
|
2023-09-02 12:34:23 +08:00
|
|
|
const good = createMemo(
|
|
|
|
() =>
|
2023-09-03 05:40:39 +08:00
|
|
|
latencyList().filter(
|
|
|
|
(latency) =>
|
|
|
|
latency > latencyQualityMap().NOT_CONNECTED &&
|
|
|
|
latency <= latencyQualityMap().MEDIUM,
|
2023-09-02 12:34:23 +08:00
|
|
|
).length,
|
|
|
|
)
|
|
|
|
const middle = createMemo(
|
|
|
|
() =>
|
2023-09-03 05:40:39 +08:00
|
|
|
latencyList().filter(
|
|
|
|
(latency) =>
|
2023-09-03 13:36:24 +08:00
|
|
|
latency > latencyQualityMap().MEDIUM &&
|
2023-09-03 05:40:39 +08:00
|
|
|
latency <= latencyQualityMap().HIGH,
|
2023-09-03 03:56:04 +08:00
|
|
|
).length,
|
2023-09-02 12:34:23 +08:00
|
|
|
)
|
|
|
|
const slow = createMemo(
|
2023-09-03 03:56:04 +08:00
|
|
|
() =>
|
2023-09-03 05:40:39 +08:00
|
|
|
latencyList().filter((latency) => latency > latencyQualityMap().HIGH)
|
|
|
|
.length,
|
2023-09-02 12:34:23 +08:00
|
|
|
)
|
|
|
|
const notConnected = createMemo(
|
|
|
|
() =>
|
2023-09-03 05:40:39 +08:00
|
|
|
latencyList().filter(
|
2023-09-04 01:12:29 +08:00
|
|
|
(latency) => latency === latencyQualityMap().NOT_CONNECTED,
|
2023-09-02 12:34:23 +08:00
|
|
|
).length,
|
|
|
|
)
|
|
|
|
|
2023-09-02 12:05:31 +08:00
|
|
|
return (
|
2023-09-25 22:39:36 +08:00
|
|
|
<div class="flex items-center gap-2 py-2">
|
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-04 01:12:29 +08:00
|
|
|
width: `${(good() * 100) / all()}%`, // cant use tw class, otherwise dynamic classname won't be generated
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
2023-09-04 01:12:29 +08:00
|
|
|
/>
|
2023-09-02 12:05:31 +08:00
|
|
|
<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
|
|
|
}}
|
2023-09-04 01:12:29 +08:00
|
|
|
/>
|
2023-09-02 12:05:31 +08:00
|
|
|
<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
|
|
|
}}
|
2023-09-04 01:12:29 +08:00
|
|
|
/>
|
2023-09-02 12:05:31 +08:00
|
|
|
<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
|
|
|
}}
|
2023-09-04 01:12:29 +08:00
|
|
|
/>
|
2023-09-02 12:05:31 +08:00
|
|
|
</div>
|
2023-09-03 06:08:53 +08:00
|
|
|
|
|
|
|
<Latency name={props.now} />
|
2023-09-02 12:05:31 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|