metacubexd/src/components/ProxyPreviewDots.tsx

73 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-09-02 12:05:31 +08:00
import { For } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Latency } from '~/components'
import { latencyQualityMap, useProxies } from '~/signals'
2023-09-02 12:05:31 +08:00
const LatencyDots = (props: {
name: string
latency?: number
selected: boolean
}) => {
let dotClassName = props.selected
2023-09-02 12:05:31 +08:00
? 'bg-white border-4 border-success'
: 'bg-success'
if (
typeof props.latency !== 'number' ||
props.latency === latencyQualityMap().NOT_CONNECTED
) {
dotClassName = props.selected
2023-09-02 12:05:31 +08:00
? 'bg-white border-4 border-neutral'
: 'bg-neutral'
} 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('h-4 w-4 rounded-full', dotClassName)}
title={props.name}
/>
)
2023-09-02 12:05:31 +08:00
}
export const ProxyPreviewDots = (props: {
proxyNameList: string[]
now?: string
}) => {
const { latencyMap } = useProxies()
2023-09-02 12:05:31 +08:00
return (
<div class="flex items-center gap-2 py-2">
<div class="flex flex-1 flex-wrap items-center gap-1">
<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
return (
<LatencyDots
name={name}
latency={latency}
selected={isSelected}
/>
)
}}
</For>
</div>
<Latency name={props.now} />
2023-09-02 12:05:31 +08:00
</div>
)
}