metacubexd/src/components/ProxyPreviewDots.tsx

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-09-02 12:05:31 +08:00
import { For } from 'solid-js'
import { twMerge } from 'tailwind-merge'
2023-09-03 03:56:04 +08:00
import {
LATENCY_QUALITY_MAP_HTTP,
LATENCY_QUALITY_MAP_HTTPS,
} from '~/constants'
import { isLatencyTestByHttps, useProxies } from '~/signals'
2023-09-02 12:05:31 +08:00
const DelayDots = (p: { delay: number | undefined; selected: boolean }) => {
2023-09-03 03:56:04 +08:00
const delayMap = isLatencyTestByHttps()
? LATENCY_QUALITY_MAP_HTTP
: LATENCY_QUALITY_MAP_HTTPS
2023-09-02 12:05:31 +08:00
let dotClassName = p.selected
? 'bg-white border-4 border-success'
: 'bg-success'
2023-09-03 03:56:04 +08:00
if (typeof p.delay !== 'number' || p.delay === delayMap.NOT_CONNECTED) {
2023-09-02 12:05:31 +08:00
dotClassName = p.selected
? 'bg-white border-4 border-neutral'
: 'bg-neutral'
2023-09-03 03:56:04 +08:00
} else if (p.delay > delayMap.HIGH) {
2023-09-02 12:05:31 +08:00
dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error'
2023-09-03 03:56:04 +08:00
} else if (p.delay > delayMap.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>
}
export const ProxyPreviewDots = (props: {
proxyNameList: string[]
now?: string
}) => {
const { delayMap } = useProxies()
2023-09-02 12:05:31 +08:00
return (
<div class="flex w-full flex-wrap items-center">
<For
each={props.proxyNameList.map((name): [string, number] => [
name,
delayMap()[name],
])}
>
{([name, delay]) => {
const isSelected = props.now === name
2023-09-02 12:05:31 +08:00
return <DelayDots delay={delay} selected={isSelected} />
}}
</For>
</div>
)
}