2023-09-02 12:05:31 +08:00
|
|
|
import { For } from 'solid-js'
|
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-03 05:35:08 +08:00
|
|
|
import { latencyQualityMap, useProxies } from '~/signals'
|
2023-09-02 12:05:31 +08:00
|
|
|
|
2023-09-03 05:40:39 +08:00
|
|
|
const LatencyDots = (p: { latency: number | undefined; selected: boolean }) => {
|
2023-09-02 12:05:31 +08:00
|
|
|
let dotClassName = p.selected
|
|
|
|
? 'bg-white border-4 border-success'
|
|
|
|
: 'bg-success'
|
|
|
|
|
2023-09-03 05:35:08 +08:00
|
|
|
if (
|
2023-09-03 05:40:39 +08:00
|
|
|
typeof p.latency !== 'number' ||
|
|
|
|
p.latency === latencyQualityMap().NOT_CONNECTED
|
2023-09-03 05:35:08 +08:00
|
|
|
) {
|
2023-09-02 12:05:31 +08:00
|
|
|
dotClassName = p.selected
|
|
|
|
? 'bg-white border-4 border-neutral'
|
|
|
|
: 'bg-neutral'
|
2023-09-03 05:40:39 +08:00
|
|
|
} else if (p.latency > latencyQualityMap().HIGH) {
|
2023-09-02 12:05:31 +08:00
|
|
|
dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error'
|
2023-09-03 05:40:39 +08:00
|
|
|
} else if (p.latency > latencyQualityMap().MEDIUM) {
|
2023-09-02 12:05:31 +08:00
|
|
|
dotClassName = p.selected
|
|
|
|
? 'bg-white border-4 border-warning'
|
|
|
|
: 'bg-warning'
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div class={twMerge('m-1 h-4 w-4 rounded-full', dotClassName)}></div>
|
|
|
|
}
|
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const ProxyPreviewDots = (props: {
|
|
|
|
proxyNameList: string[]
|
|
|
|
now?: string
|
|
|
|
}) => {
|
2023-09-03 05:35:08 +08:00
|
|
|
const { latencyMap } = useProxies()
|
2023-09-02 12:05:31 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div class="flex w-full flex-wrap items-center">
|
2023-09-02 15:00:13 +08:00
|
|
|
<For
|
|
|
|
each={props.proxyNameList.map((name): [string, number] => [
|
|
|
|
name,
|
2023-09-03 05:35:08 +08:00
|
|
|
latencyMap()[name],
|
2023-09-02 15:00:13 +08:00
|
|
|
])}
|
|
|
|
>
|
2023-09-03 05:40:39 +08:00
|
|
|
{([name, latency]) => {
|
2023-09-02 15:00:13 +08:00
|
|
|
const isSelected = props.now === name
|
2023-09-02 12:05:31 +08:00
|
|
|
|
2023-09-03 05:40:39 +08:00
|
|
|
return <LatencyDots latency={latency} selected={isSelected} />
|
2023-09-02 12:05:31 +08:00
|
|
|
}}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|