diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index 07c371d..9ebbca6 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -26,7 +26,6 @@ import { proxiesOrderingType, useProxies, } from '~/signals' -import type { Proxy } from '~/types' enum ActiveTab { proxyProviders = 'proxyProviders', @@ -37,7 +36,7 @@ export default () => { const [t] = useI18n() const { proxies, - setProxyGroupByProxyName, + selectProxyInGroup, latencyTestByProxyGroupName, latencyMap, proxyProviders, @@ -50,10 +49,6 @@ export default () => { 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)) @@ -153,11 +148,11 @@ export default () => {
- {(proxy) => { + {(proxyGroup) => { const sortedProxyNames = createMemo(() => filterProxiesByAvailability( sortProxiesByOrderingType( - proxy.all ?? [], + proxyGroup.all ?? [], latencyMap(), proxiesOrderingType(), ), @@ -170,18 +165,20 @@ export default () => { <>
- {proxy.name} -
{proxy.all?.length}
+ {proxyGroup.name} +
+ {proxyGroup.all?.length} +
- {proxy.type} {proxy.now?.length > 0 && ` :: ${proxy.now}`} + {proxyGroup.type}{' '} + {proxyGroup.now?.length > 0 && ` :: ${proxyGroup.now}`}
- + @@ -203,14 +201,16 @@ export default () => { return ( setCollapsedMap(proxy.name, val)} + onCollapse={(val) => setCollapsedMap(proxyGroup.name, val)} > void onProxyNodeClick(proxy, name)} + now={proxyGroup.now} + onClick={(name) => + void selectProxyInGroup(proxyGroup, name) + } /> ) diff --git a/src/signals/connections.ts b/src/signals/connections.ts index 324bef2..8e48cfd 100644 --- a/src/signals/connections.ts +++ b/src/signals/connections.ts @@ -47,10 +47,11 @@ export const useConnections = () => { rawConns, activeConnections(), ) - const allConns = mergeAllConnections(activeConns) + + mergeAllConnections(activeConnections()) if (!paused()) { - const closedConns = diffClosedConnections(activeConns, allConns) + const closedConns = diffClosedConnections(activeConns, allConnections()) setActiveConnections(activeConns) setClosedConnections( @@ -58,8 +59,8 @@ export const useConnections = () => { ) } - setAllConnections( - allConns.slice( + setAllConnections((allConnections) => + allConnections.slice( -(activeConns.length + CONNECTIONS_TABLE_MAX_CLOSED_ROWS), ), ) @@ -101,12 +102,12 @@ export const restructRawMsgToConnection = ( } export const mergeAllConnections = (activeConns: Connection[]) => { - return unionWith(allConnections(), activeConns, (a, b) => a.id === b.id) + setAllConnections((allConnections) => + unionWith(allConnections, activeConns, (a, b) => a.id === b.id), + ) } const diffClosedConnections = ( activeConns: Connection[], allConns: Connection[], -) => { - return differenceWith(allConns, activeConns, (a, b) => a.id === b.id) -} +) => differenceWith(allConns, activeConns, (a, b) => a.id === b.id) diff --git a/src/signals/proxies.ts b/src/signals/proxies.ts index 9a9bb0b..8df38cf 100644 --- a/src/signals/proxies.ts +++ b/src/signals/proxies.ts @@ -13,7 +13,6 @@ import { latencyQualityMap, latencyTestTimeoutDuration, latestConnectionMsg, - mergeAllConnections, restructRawMsgToConnection, urlForLatencyTest, } from '~/signals' @@ -90,11 +89,9 @@ export const useProxies = () => { }) } - const setProxyGroupByProxyName = async (proxy: Proxy, proxyName: string) => { - const proxyGroupList = proxies().slice() - const proxyGroup = proxyGroupList.find((i) => i.name === proxy.name)! - + const selectProxyInGroup = async (proxy: Proxy, proxyName: string) => { await selectProxyInGroupAPI(proxy.name, proxyName) + await updateProxies() if (autoCloseConns()) { // we don't use activeConns from useConnection here for better performance, @@ -111,13 +108,9 @@ export const useProxies = () => { closeSingleConnectionAPI(id) } }) - mergeAllConnections(activeConns) } }) } - - proxyGroup.now = proxyName - setProxies(proxyGroupList) } const latencyTestByProxyGroupName = async (proxyGroupName: string) => { @@ -159,7 +152,7 @@ export const useProxies = () => { latencyMap, proxyNodeMap, updateProxies, - setProxyGroupByProxyName, + selectProxyInGroup, updateProviderByProviderName, updateAllProvider, healthCheckByProviderName,