2023-09-24 17:10:01 +08:00
|
|
|
import { IconBrandSpeedtest } from '@tabler/icons-solidjs'
|
2023-09-05 02:42:54 +08:00
|
|
|
import { createMemo, Show } from 'solid-js'
|
2023-08-30 23:02:55 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-24 17:10:01 +08:00
|
|
|
import { Button, Latency } from '~/components'
|
2023-09-05 02:42:54 +08:00
|
|
|
import { filterSpecialProxyType, formatProxyType } from '~/helpers'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { useProxies } from '~/signals'
|
2023-08-30 23:02:55 +08:00
|
|
|
|
2023-09-03 05:35:08 +08:00
|
|
|
export const ProxyNodeCard = (props: {
|
2023-08-30 23:02:55 +08:00
|
|
|
proxyName: string
|
|
|
|
isSelected?: boolean
|
|
|
|
onClick?: () => void
|
|
|
|
}) => {
|
2023-09-24 18:05:52 +08:00
|
|
|
const { proxyLatencyTest, proxyLatencyTestingMap } = useProxies()
|
2023-08-30 23:02:55 +08:00
|
|
|
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-09-05 02:42:54 +08:00
|
|
|
const specialType = () =>
|
|
|
|
filterSpecialProxyType(proxyNode()?.type)
|
|
|
|
? proxyNode()?.xudp
|
|
|
|
? 'xudp'
|
|
|
|
: proxyNode()?.udp
|
|
|
|
? 'udp'
|
|
|
|
: null
|
|
|
|
: null
|
2023-08-31 00:00:50 +08:00
|
|
|
|
2023-08-30 23:02:55 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class={twMerge(
|
2023-10-19 23:59:22 +08:00
|
|
|
'card card-bordered tooltip-bottom flex flex-col justify-between gap-1 border-neutral-focus bg-neutral p-2 text-neutral-content',
|
2023-09-01 10:02:47 +08:00
|
|
|
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
|
|
|
)}
|
2023-09-24 17:10:01 +08:00
|
|
|
onClick={onClick}
|
2023-09-27 16:47:51 +08:00
|
|
|
title={proxyName}
|
2023-08-30 23:02:55 +08:00
|
|
|
>
|
2023-09-24 17:10:01 +08:00
|
|
|
<div class="flex items-center justify-between gap-2">
|
2023-10-19 23:59:22 +08:00
|
|
|
<span class="text-left text-sm">{proxyName}</span>
|
2023-09-24 17:10:01 +08:00
|
|
|
|
|
|
|
<Button
|
2023-09-27 16:47:51 +08:00
|
|
|
class="btn-circle btn-ghost h-auto min-h-0 w-auto"
|
2023-09-24 18:05:52 +08:00
|
|
|
icon={
|
|
|
|
<IconBrandSpeedtest
|
2023-09-27 16:47:51 +08:00
|
|
|
size={20}
|
2023-09-24 18:05:52 +08:00
|
|
|
class={twMerge(
|
|
|
|
proxyLatencyTestingMap()[proxyName] &&
|
|
|
|
'animate-pulse text-success',
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
}
|
2023-09-24 17:10:01 +08:00
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation()
|
|
|
|
|
2023-09-26 01:28:24 +08:00
|
|
|
void proxyLatencyTest(proxyName, proxyNode().provider)
|
2023-09-24 17:10:01 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-08-31 00:00:50 +08:00
|
|
|
<div class="flex items-center justify-between gap-1">
|
2023-09-01 10:29:12 +08:00
|
|
|
<div
|
|
|
|
class={twMerge(
|
2023-10-19 23:59:22 +08:00
|
|
|
'text-xs text-slate-500',
|
2023-09-01 10:29:12 +08:00
|
|
|
isSelected && 'text-primary',
|
|
|
|
)}
|
|
|
|
>
|
2023-09-01 12:10:34 +08:00
|
|
|
{formatProxyType(proxyNode()?.type)}
|
2023-09-24 17:10:01 +08:00
|
|
|
|
2023-09-05 02:42:54 +08:00
|
|
|
<Show when={specialType()}>{` :: ${specialType()}`}</Show>
|
2023-08-30 23:54:49 +08:00
|
|
|
</div>
|
2023-09-24 17:10:01 +08:00
|
|
|
|
2023-09-02 11:52:51 +08:00
|
|
|
<div class="text-xs">
|
2023-09-03 03:56:04 +08:00
|
|
|
<Latency name={props.proxyName} />
|
2023-09-02 11:52:51 +08:00
|
|
|
</div>
|
2023-08-30 23:54:49 +08:00
|
|
|
</div>
|
2023-08-30 23:02:55 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|