2023-09-02 12:05:31 +08:00
|
|
|
import { For } from 'solid-js'
|
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-04 20:29:08 +08:00
|
|
|
import { Latency } from '~/components'
|
2023-09-03 05:35:08 +08:00
|
|
|
import { latencyQualityMap, useProxies } from '~/signals'
|
2023-09-02 12:05:31 +08:00
|
|
|
|
2023-09-04 01:12:29 +08:00
|
|
|
const LatencyDots = (props: {
|
|
|
|
latency: number | undefined
|
|
|
|
selected: boolean
|
|
|
|
}) => {
|
|
|
|
let dotClassName = props.selected
|
2023-09-02 12:05:31 +08:00
|
|
|
? 'bg-white border-4 border-success'
|
|
|
|
: 'bg-success'
|
|
|
|
|
2023-09-03 05:35:08 +08:00
|
|
|
if (
|
2023-09-04 01:12:29 +08:00
|
|
|
typeof props.latency !== 'number' ||
|
|
|
|
props.latency === latencyQualityMap().NOT_CONNECTED
|
2023-09-03 05:35:08 +08:00
|
|
|
) {
|
2023-09-04 01:12:29 +08:00
|
|
|
dotClassName = props.selected
|
2023-09-02 12:05:31 +08:00
|
|
|
? 'bg-white border-4 border-neutral'
|
|
|
|
: 'bg-neutral'
|
2023-09-04 01:12:29 +08:00
|
|
|
} else if (props.latency > latencyQualityMap().HIGH) {
|
|
|
|
dotClassName = props.selected
|
|
|
|
? 'bg-white border-4 border-error'
|
|
|
|
: 'bg-error'
|
|
|
|
} else if (props.latency > latencyQualityMap().MEDIUM) {
|
|
|
|
dotClassName = props.selected
|
2023-09-02 12:05:31 +08:00
|
|
|
? '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 (
|
2023-09-04 20:29:08 +08:00
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
<div class="flex flex-1 flex-wrap items-center">
|
|
|
|
<For
|
|
|
|
each={props.proxyNameList.map((name): [string, number] => [
|
|
|
|
name,
|
|
|
|
latencyMap()[name],
|
|
|
|
])}
|
|
|
|
>
|
|
|
|
{([name, latency]) => {
|
|
|
|
const isSelected = props.now === name
|
2023-09-02 12:05:31 +08:00
|
|
|
|
2023-09-04 20:29:08 +08:00
|
|
|
return <LatencyDots latency={latency} selected={isSelected} />
|
|
|
|
}}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Latency name={props.now} />
|
2023-09-02 12:05:31 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|