mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-25 10:05:34 +08:00
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
|
import { For } from 'solid-js'
|
||
|
import { twMerge } from 'tailwind-merge'
|
||
|
import { DELAY } from '~/config/enum'
|
||
|
import { useProxies } from '~/signals/proxies'
|
||
|
|
||
|
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>
|
||
|
}
|
||
|
|
||
|
export default (props: { proxyNameList: string[]; now?: string }) => {
|
||
|
const { proxyNodeMap } = useProxies()
|
||
|
|
||
|
return (
|
||
|
<div class="flex w-full flex-wrap items-center">
|
||
|
<For each={props.proxyNameList.map((name) => proxyNodeMap()[name]!)}>
|
||
|
{(proxy) => {
|
||
|
const delay = proxy?.delay
|
||
|
const isSelected = props.now === proxy.name
|
||
|
|
||
|
return <DelayDots delay={delay} selected={isSelected} />
|
||
|
}}
|
||
|
</For>
|
||
|
</div>
|
||
|
)
|
||
|
}
|