From 8f8a54af0abc0dce49a6ed0ee616b0d844fad5ab Mon Sep 17 00:00:00 2001 From: kunish Date: Sun, 24 Sep 2023 17:56:24 +0800 Subject: [PATCH] refactor(proxy): move states into useProxies, rename properties --- src/components/ProxyCardGroups.tsx | 20 -------- src/components/index.ts | 1 - src/pages/Proxies.tsx | 78 ++++++++++++++++-------------- src/signals/proxies.ts | 74 +++++++++++++++++----------- 4 files changed, 88 insertions(+), 85 deletions(-) delete mode 100644 src/components/ProxyCardGroups.tsx diff --git a/src/components/ProxyCardGroups.tsx b/src/components/ProxyCardGroups.tsx deleted file mode 100644 index 371de6d..0000000 --- a/src/components/ProxyCardGroups.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { For } from 'solid-js' -import { ProxyNodeCard } from '~/components' - -export const ProxyCardGroups = (props: { - proxyNames: string[] - now?: string - onClick?: (name: string) => void -}) => { - return ( - - {(proxy) => ( - props.onClick?.(proxy))} - /> - )} - - ) -} diff --git a/src/components/index.ts b/src/components/index.ts index fa6f27e..d7b4635 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -9,7 +9,6 @@ export * from './LogoText' export * from './LogsSettingsModal' export * from './Modal' export * from './ProxiesSettingsModal' -export * from './ProxyCardGroups' export * from './ProxyNodeCard' export * from './ProxyNodePreview' export * from './ProxyPreviewBar' diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index ca95c6b..443c61d 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -9,7 +9,7 @@ import { Button, Collapse, ProxiesSettingsModal, - ProxyCardGroups, + ProxyNodeCard, ProxyNodePreview, RenderInTwoColumns, SubscriptionInfo, @@ -17,7 +17,6 @@ import { import { filterProxiesByAvailability, sortProxiesByOrderingType, - useStringBooleanMap, } from '~/helpers' import { useI18n } from '~/i18n' import { @@ -41,48 +40,46 @@ export default () => { fetchProxies, proxies, selectProxyInGroup, - proxyGroupLatencyTest, latencyMap, proxyProviders, updateProviderByProviderName, updateAllProvider, - healthCheckByProviderName, + proxyGroupLatencyTest, + proxyProviderLatencyTest, collapsedMap, setCollapsedMap, latencyTestingMap, - setLatencyTestingMap, + healthCheckingMap, + isAllProviderUpdating, + updatingMap, } = useProxies() onMount(fetchProxies) - const onLatencyTestClick = async (e: MouseEvent, name: string) => { + const onProxyGroupLatencyTestClick = async ( + e: MouseEvent, + groupName: string, + ) => { e.stopPropagation() - void setLatencyTestingMap(name, () => proxyGroupLatencyTest(name)) + void proxyGroupLatencyTest(groupName) } - const { map: healthCheckingMap, setWithCallback: setHealthCheckingMap } = - useStringBooleanMap() - const { map: updatingMap, setWithCallback: setUpdatingMap } = - useStringBooleanMap() - const [isAllProviderUpdating, setIsAllProviderUpdating] = createSignal(false) - - const onHealthCheckClick = (e: MouseEvent, name: string) => { + const onProxyProviderLatencyTestClick = ( + e: MouseEvent, + providerName: string, + ) => { e.stopPropagation() - void setHealthCheckingMap(name, () => healthCheckByProviderName(name)) + void proxyProviderLatencyTest(providerName) } - const onUpdateProviderClick = (e: MouseEvent, name: string) => { + const onUpdateProxyProviderClick = (e: MouseEvent, providerName: string) => { e.stopPropagation() - void setUpdatingMap(name, () => updateProviderByProviderName(name)) + void updateProviderByProviderName(providerName) } const onUpdateAllProviderClick = async (e: MouseEvent) => { e.stopPropagation() - setIsAllProviderUpdating(true) - try { - await updateAllProvider() - } catch {} - setIsAllProviderUpdating(false) + void updateAllProvider() } const [activeTab, setActiveTab] = createSignal(ActiveTab.proxies) @@ -163,7 +160,7 @@ export default () => { const title = ( <> -
+
{proxyGroup.name}
@@ -174,7 +171,9 @@ export default () => {