2023-09-02 00:09:41 +08:00
|
|
|
import { useI18n } from '@solid-primitives/i18n'
|
2023-09-02 16:58:22 +08:00
|
|
|
import { IconBrandSpeedtest } from '@tabler/icons-solidjs'
|
2023-09-05 15:38:42 +08:00
|
|
|
import { Show } from 'solid-js'
|
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-03 03:26:29 +08:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Collapse,
|
|
|
|
ForTwoColumns,
|
|
|
|
ProxyCardGroups,
|
|
|
|
ProxyNodePreview,
|
|
|
|
} from '~/components'
|
2023-09-05 15:38:42 +08:00
|
|
|
import { sortProxiesByOrderingType, useStringBooleanMap } from '~/helpers'
|
2023-09-04 19:12:27 +08:00
|
|
|
import {
|
|
|
|
proxiesOrderingType,
|
|
|
|
renderProxiesInSamePage,
|
|
|
|
useProxies,
|
|
|
|
} from '~/signals'
|
2023-08-29 20:20:01 +08:00
|
|
|
import type { Proxy } from '~/types'
|
2023-09-04 19:12:27 +08:00
|
|
|
import ProxyProvider from './ProxyProvider'
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-29 14:44:49 +08:00
|
|
|
export default () => {
|
2023-09-02 00:09:41 +08:00
|
|
|
const [t] = useI18n()
|
2023-09-03 05:35:08 +08:00
|
|
|
const {
|
|
|
|
proxies,
|
|
|
|
setProxyGroupByProxyName,
|
2023-09-03 05:40:39 +08:00
|
|
|
latencyTestByProxyGroupName,
|
2023-09-03 05:35:08 +08:00
|
|
|
latencyMap,
|
|
|
|
} = useProxies()
|
2023-08-30 23:02:55 +08:00
|
|
|
|
2023-09-05 15:38:42 +08:00
|
|
|
const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap()
|
|
|
|
const { map: speedTestingMap, setWithCallback: setSpeedTestingMap } =
|
|
|
|
useStringBooleanMap()
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-29 20:20:01 +08:00
|
|
|
const onProxyNodeClick = async (proxy: Proxy, proxyName: string) => {
|
2023-09-03 20:23:02 +08:00
|
|
|
void setProxyGroupByProxyName(proxy, proxyName)
|
2023-08-29 20:20:01 +08:00
|
|
|
}
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-09-05 15:38:42 +08:00
|
|
|
const onSpeedTestClick = async (e: MouseEvent, name: string) => {
|
|
|
|
e.stopPropagation()
|
|
|
|
setSpeedTestingMap(
|
|
|
|
name,
|
|
|
|
async () => await latencyTestByProxyGroupName(name),
|
2023-09-04 17:57:20 +08:00
|
|
|
)
|
2023-08-30 11:01:19 +08:00
|
|
|
}
|
|
|
|
|
2023-08-24 04:20:53 +08:00
|
|
|
return (
|
2023-09-04 19:12:27 +08:00
|
|
|
<>
|
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
<h1 class="flex h-8 items-center pb-2 text-lg font-semibold">
|
|
|
|
{t('proxies')}
|
|
|
|
</h1>
|
|
|
|
<ForTwoColumns
|
|
|
|
subChild={proxies().map((proxy) => {
|
|
|
|
const sortedProxyNames = sortProxiesByOrderingType(
|
|
|
|
proxy.all ?? [],
|
|
|
|
latencyMap(),
|
|
|
|
proxiesOrderingType(),
|
|
|
|
)
|
2023-09-03 06:08:53 +08:00
|
|
|
|
2023-09-04 19:12:27 +08:00
|
|
|
const title = (
|
|
|
|
<>
|
2023-09-05 16:13:11 +08:00
|
|
|
<div class="mr-8 flex items-center justify-between">
|
2023-09-04 19:12:27 +08:00
|
|
|
<span>{proxy.name}</span>
|
|
|
|
<Button
|
|
|
|
class="btn-circle btn-sm"
|
|
|
|
onClick={(e) => onSpeedTestClick(e, proxy.name)}
|
|
|
|
>
|
2023-09-05 15:38:42 +08:00
|
|
|
<IconBrandSpeedtest
|
|
|
|
class={twMerge(
|
|
|
|
speedTestingMap()[proxy.name] && 'animate-pulse',
|
|
|
|
)}
|
|
|
|
/>
|
2023-09-04 19:12:27 +08:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div class="text-sm text-slate-500">
|
2023-09-05 01:30:17 +08:00
|
|
|
{proxy.type} {proxy.now?.length > 0 && ` :: ${proxy.now}`}
|
2023-09-04 19:12:27 +08:00
|
|
|
</div>
|
|
|
|
<Show when={!collapsedMap()[`group-${proxy.name}`]}>
|
|
|
|
<ProxyNodePreview
|
|
|
|
proxyNameList={sortedProxyNames}
|
|
|
|
now={proxy.now}
|
|
|
|
/>
|
|
|
|
</Show>
|
|
|
|
</>
|
|
|
|
)
|
2023-09-02 16:58:22 +08:00
|
|
|
|
2023-09-04 19:12:27 +08:00
|
|
|
const content = (
|
|
|
|
<ProxyCardGroups
|
|
|
|
proxyNames={sortedProxyNames}
|
|
|
|
now={proxy.now}
|
|
|
|
onClick={(name) => {
|
|
|
|
void onProxyNodeClick(proxy, name)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
2023-09-02 16:58:22 +08:00
|
|
|
|
2023-09-04 19:12:27 +08:00
|
|
|
return (
|
|
|
|
<Collapse
|
|
|
|
isOpen={collapsedMap()[`group-${proxy.name}`]}
|
|
|
|
title={title}
|
|
|
|
content={content}
|
|
|
|
onCollapse={(val) =>
|
2023-09-05 15:38:42 +08:00
|
|
|
setCollapsedMap(`group-${proxy.name}`, val)
|
2023-09-04 19:12:27 +08:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Show when={renderProxiesInSamePage()}>
|
|
|
|
<div class="divider"></div>
|
|
|
|
<ProxyProvider />
|
|
|
|
</Show>
|
|
|
|
</>
|
2023-08-24 04:20:53 +08:00
|
|
|
)
|
|
|
|
}
|