2023-08-30 23:54:49 +08:00
|
|
|
import { createMemo } from 'solid-js'
|
2023-08-30 23:02:55 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
|
|
|
import { useProxies } from '~/signals/proxies'
|
|
|
|
|
|
|
|
export default (props: {
|
|
|
|
proxyName: string
|
|
|
|
isSelected?: boolean
|
|
|
|
onClick?: () => void
|
|
|
|
}) => {
|
|
|
|
const { proxyName, isSelected, onClick } = props
|
2023-08-30 23:54:49 +08:00
|
|
|
const { delayMap, proxyNodeMap } = useProxies()
|
|
|
|
const proxyNode = createMemo(() => proxyNodeMap()[proxyName])
|
2023-08-31 00:00:50 +08:00
|
|
|
|
2023-08-30 23:02:55 +08:00
|
|
|
const Delay = (proxyname: string) => {
|
|
|
|
const delay = delayMap()[proxyname]
|
|
|
|
|
|
|
|
if (typeof delay !== 'number' || delay === 0) {
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
2023-08-31 00:00:50 +08:00
|
|
|
let textClassName = 'text-green-500'
|
|
|
|
|
2023-08-30 23:54:49 +08:00
|
|
|
if (delay > 500) {
|
|
|
|
textClassName = 'text-red-500'
|
|
|
|
} else if (delay > 200) {
|
|
|
|
textClassName = 'text-yellow-500'
|
|
|
|
}
|
|
|
|
|
|
|
|
return <span class={textClassName}>{delay}ms</span>
|
2023-08-30 23:02:55 +08:00
|
|
|
}
|
|
|
|
|
2023-08-31 00:00:50 +08:00
|
|
|
const formatProxyType = (type: string) => {
|
|
|
|
const t = type.toLowerCase()
|
|
|
|
|
|
|
|
if (t === 'shadowsocks') {
|
|
|
|
return 'SS'
|
|
|
|
}
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2023-08-30 23:02:55 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class={twMerge(
|
2023-08-31 00:00:50 +08:00
|
|
|
'card card-bordered tooltip tooltip-bottom card-compact flex gap-1 p-4',
|
2023-08-30 23:02:55 +08:00
|
|
|
isSelected
|
|
|
|
? 'border-primary bg-success-content text-success'
|
|
|
|
: 'border-secondary',
|
2023-08-30 23:36:25 +08:00
|
|
|
onClick && 'cursor-pointer',
|
2023-08-30 23:02:55 +08:00
|
|
|
)}
|
|
|
|
onClick={() => onClick?.()}
|
2023-08-30 23:36:25 +08:00
|
|
|
data-tip={proxyName}
|
2023-08-30 23:02:55 +08:00
|
|
|
>
|
2023-08-31 00:00:50 +08:00
|
|
|
<div class="truncate text-left">{proxyName}</div>
|
|
|
|
<div class="flex items-center justify-between gap-1">
|
|
|
|
<div class="truncate text-xs text-slate-500">
|
|
|
|
{formatProxyType(proxyNode().type)}
|
2023-08-30 23:54:49 +08:00
|
|
|
{proxyNode().udp ? ' :: udp' : ''}
|
|
|
|
</div>
|
2023-08-31 00:00:50 +08:00
|
|
|
<div class="text-xs">{Delay(proxyName)}</div>
|
2023-08-30 23:54:49 +08:00
|
|
|
</div>
|
2023-08-30 23:02:55 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|