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'
|
2023-09-01 15:10:57 +08:00
|
|
|
import { DELAY } from '~/config/enum'
|
2023-08-30 23:02:55 +08:00
|
|
|
import { useProxies } from '~/signals/proxies'
|
|
|
|
|
|
|
|
export default (props: {
|
|
|
|
proxyName: string
|
|
|
|
isSelected?: boolean
|
|
|
|
onClick?: () => void
|
|
|
|
}) => {
|
|
|
|
const { proxyName, isSelected, onClick } = props
|
2023-09-01 12:10:34 +08:00
|
|
|
const { proxyNodeMap } = useProxies()
|
2023-08-30 23:54:49 +08:00
|
|
|
const proxyNode = createMemo(() => proxyNodeMap()[proxyName])
|
2023-08-31 00:00:50 +08:00
|
|
|
|
2023-09-01 12:10:34 +08:00
|
|
|
const Delay = (delay: number | undefined) => {
|
2023-09-01 15:10:57 +08:00
|
|
|
if (typeof delay !== 'number' || delay === DELAY.NOT_CONNECTED) {
|
2023-08-30 23:02:55 +08:00
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
2023-09-01 15:10:57 +08:00
|
|
|
let textClassName = 'text-success'
|
|
|
|
|
|
|
|
if (delay > DELAY.HIGH) {
|
|
|
|
textClassName = 'text-error'
|
|
|
|
} else if (delay > DELAY.MEDIUM) {
|
|
|
|
textClassName = 'text-warning'
|
|
|
|
}
|
2023-08-30 23:54:49 +08:00
|
|
|
|
|
|
|
return <span class={textClassName}>{delay}ms</span>
|
2023-08-30 23:02:55 +08:00
|
|
|
}
|
|
|
|
|
2023-09-01 12:10:34 +08:00
|
|
|
const formatProxyType = (type = '') => {
|
2023-08-31 00:00:50 +08:00
|
|
|
const t = type.toLowerCase()
|
|
|
|
|
2023-08-31 22:49:34 +08:00
|
|
|
if (t.includes('shadowsocks')) {
|
|
|
|
return t.replace('shadowsocks', 'ss')
|
2023-08-31 00:00:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2023-08-30 23:02:55 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class={twMerge(
|
2023-09-01 10:02:47 +08:00
|
|
|
'card card-bordered tooltip tooltip-bottom card-compact flex gap-1 border-neutral-focus bg-neutral p-3 text-neutral-content',
|
|
|
|
isSelected && 'border-primary bg-primary-content text-primary',
|
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">
|
2023-09-01 10:29:12 +08:00
|
|
|
<div
|
|
|
|
class={twMerge(
|
|
|
|
'truncate text-xs text-slate-500',
|
|
|
|
isSelected && 'text-primary',
|
|
|
|
)}
|
|
|
|
>
|
2023-09-01 12:10:34 +08:00
|
|
|
{formatProxyType(proxyNode()?.type)}
|
|
|
|
{proxyNode()?.udp && ' :: udp'}
|
2023-08-30 23:54:49 +08:00
|
|
|
</div>
|
2023-09-01 12:10:34 +08:00
|
|
|
<div class="text-xs">{Delay(proxyNode()?.delay)}</div>
|
2023-08-30 23:54:49 +08:00
|
|
|
</div>
|
2023-08-30 23:02:55 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|