2023-09-02 12:05:31 +08:00
|
|
|
import { For } from 'solid-js'
|
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { DELAY } from '~/constants'
|
|
|
|
import { useProxies } from '~/signals'
|
2023-09-02 12:05:31 +08:00
|
|
|
|
|
|
|
const DelayDots = (p: { delay: number | undefined; selected: boolean }) => {
|
|
|
|
let dotClassName = p.selected
|
|
|
|
? 'bg-white border-4 border-success'
|
|
|
|
: 'bg-success'
|
|
|
|
|
|
|
|
if (typeof p.delay !== 'number' || p.delay === DELAY.NOT_CONNECTED) {
|
|
|
|
dotClassName = p.selected
|
|
|
|
? 'bg-white border-4 border-neutral'
|
|
|
|
: 'bg-neutral'
|
|
|
|
} else if (p.delay > DELAY.HIGH) {
|
|
|
|
dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error'
|
|
|
|
} else if (p.delay > DELAY.MEDIUM) {
|
|
|
|
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-02 15:00:13 +08:00
|
|
|
const { delayMap } = 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,
|
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|