import { useI18n } from '@solid-primitives/i18n' import { IconBrandSpeedtest, IconReload, IconSettings, } from '@tabler/icons-solidjs' import { For, Show, createMemo, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { Button, Collapse, ProxiesSettingsModal, ProxyCardGroups, ProxyNodePreview, RenderInTwoColumns, SubscriptionInfo, } from '~/components' import { MODAL } from '~/constants' import { filterProxiesByAvailability, formatTimeFromNow, sortProxiesByOrderingType, useStringBooleanMap, } from '~/helpers' import { hideUnAvailableProxies, proxiesOrderingType, useProxies, } from '~/signals' enum ActiveTab { proxyProviders = 'proxyProviders', proxies = 'proxies', } export default () => { const [t] = useI18n() const { proxies, selectProxyInGroup, latencyTestByProxyGroupName, latencyMap, proxyProviders, updateProviderByProviderName, updateAllProvider, healthCheckByProviderName, } = useProxies() const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap() const { map: latencyTestingMap, setWithCallback: setLatencyTestingMap } = useStringBooleanMap() 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.proxies) const tabs = () => [ { type: ActiveTab.proxies, name: t('proxies'), count: proxies().length, }, { type: ActiveTab.proxyProviders, name: t('proxyProviders'), count: proxyProviders().length, }, ] return (
{(tab) => ( )}
{(proxyGroup) => { const sortedProxyNames = createMemo(() => filterProxiesByAvailability( sortProxiesByOrderingType( proxyGroup.all ?? [], latencyMap(), proxiesOrderingType(), ), latencyMap(), hideUnAvailableProxies(), ), ) const title = ( <>
{proxyGroup.name}
{proxyGroup.all?.length}
{proxyGroup.type}{' '} {proxyGroup.now?.length > 0 && ` :: ${proxyGroup.now}`}
) return ( setCollapsedMap(proxyGroup.name, val)} > void selectProxyInGroup(proxyGroup, name) } /> ) }}
{(proxyProvider) => { const sortedProxyNames = createMemo(() => sortProxiesByOrderingType( proxyProvider.proxies.map((i) => i.name) ?? [], latencyMap(), proxiesOrderingType(), ), ) const title = ( <>
{proxyProvider.name}
{proxyProvider.proxies.length}
{proxyProvider.vehicleType} :: {t('updated')}{' '} {formatTimeFromNow(proxyProvider.updatedAt)}
) return ( setCollapsedMap(proxyProvider.name, val) } > ) }}
) }