import { useI18n } from '@solid-primitives/i18n' import { IconBrandSpeedtest, IconReload } from '@tabler/icons-solidjs' import { For, Show, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { Button, Collapse, ForTwoColumns, ProxyCardGroups, ProxyNodePreview, SubscriptionInfo, } from '~/components' import { formatTimeFromNow, sortProxiesByOrderingType, useStringBooleanMap, } from '~/helpers' import { proxiesOrderingType, useProxies } from '~/signals' import type { Proxy } from '~/types' enum ActiveTab { all = 'all', proxyProviders = 'proxyProviders', proxies = 'proxies', } export default () => { const [t] = useI18n() const { proxies, setProxyGroupByProxyName, latencyTestByProxyGroupName, latencyMap, proxyProviders, updateProviderByProviderName, updateAllProvider, healthCheckByProviderName, } = useProxies() const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap() const { map: latencyTestingMap, setWithCallback: setLatencyTestingMap } = useStringBooleanMap() const onProxyNodeClick = async (proxy: Proxy, proxyName: string) => { void setProxyGroupByProxyName(proxy, proxyName) } const onLatencyTestClick = async (e: MouseEvent, name: string) => { e.stopPropagation() void setLatencyTestingMap(name, () => latencyTestByProxyGroupName(name)) } const { map: healthCheckingMap, setWithCallback: setHealthCheckingMap } = useStringBooleanMap() const { map: updatingMap, setWithCallback: setUpdatingMap } = useStringBooleanMap() const [isAllProviderUpdating, setIsAllProviderUpdating] = createSignal(false) const onHealthCheckClick = (e: MouseEvent, name: string) => { e.stopPropagation() void setHealthCheckingMap(name, () => healthCheckByProviderName(name)) } const onUpdateProviderClick = (e: MouseEvent, name: string) => { e.stopPropagation() void setUpdatingMap(name, () => updateProviderByProviderName(name)) } const onUpdateAllProviderClick = async (e: MouseEvent) => { e.stopPropagation() setIsAllProviderUpdating(true) try { await updateAllProvider() } catch {} setIsAllProviderUpdating(false) } const [activeTab, setActiveTab] = createSignal(ActiveTab.all) const tabs = () => [ { type: ActiveTab.all, name: t('all'), count: proxyProviders().length + proxies().length, }, { type: ActiveTab.proxyProviders, name: t('proxyProviders'), count: proxyProviders().length, }, { type: ActiveTab.proxies, name: t('proxies'), count: proxies().length, }, ] return (
{(tab) => ( )}
{ const sortedProxyNames = sortProxiesByOrderingType( proxyProvider.proxies.map((i) => i.name) ?? [], latencyMap(), proxiesOrderingType(), ) const title = ( <>
{proxyProvider.name}
{proxyProvider.vehicleType} :: {t('updated')}{' '} {formatTimeFromNow(proxyProvider.updatedAt)}
) const content = return ( setCollapsedMap(proxyProvider.name, val)} /> ) })} />
{ const sortedProxyNames = sortProxiesByOrderingType( proxy.all ?? [], latencyMap(), proxiesOrderingType(), ) const title = ( <>
{proxy.name}
{proxy.type} {proxy.now?.length > 0 && ` :: ${proxy.now}`}
) const content = ( { void onProxyNodeClick(proxy, name) }} /> ) return ( setCollapsedMap(proxy.name, val)} /> ) })} />
) }