diff --git a/src/components/Delay.tsx b/src/components/Delay.tsx index 014b1dee..999d8ce4 100644 --- a/src/components/Delay.tsx +++ b/src/components/Delay.tsx @@ -1,21 +1,33 @@ +import { Show, createEffect, createMemo, createSignal } from 'solid-js' import { DELAY } from '~/config/enum' +import { useProxies } from '~/signals/proxies' -const Delay = (props: { delay: number | undefined }) => { - const delay = props.delay +const Delay = (props: { name?: string }) => { + const { proxyNodeMap } = useProxies() + const [textClassName, setTextClassName] = createSignal('') + const delay = createMemo(() => { + return proxyNodeMap()[props.name!]?.delay! + }) - if (typeof delay !== 'number' || delay === DELAY.NOT_CONNECTED) { - return '' - } + createEffect(() => { + setTextClassName('text-success') - let textClassName = 'text-success' + if (delay() > DELAY.HIGH) { + setTextClassName('text-error') + } else if (delay() > DELAY.MEDIUM) { + setTextClassName('text-warning') + } + }) - if (delay > DELAY.HIGH) { - textClassName = 'text-error' - } else if (delay > DELAY.MEDIUM) { - textClassName = 'text-warning' - } - - return {delay}ms + return ( + <> + + {delay()}ms + + + ) } export default Delay diff --git a/src/components/ProxyNodeCard.tsx b/src/components/ProxyNodeCard.tsx index e671c63b..770a1b97 100644 --- a/src/components/ProxyNodeCard.tsx +++ b/src/components/ProxyNodeCard.tsx @@ -44,7 +44,7 @@ export default (props: { {proxyNode()?.udp && ' :: udp'}
- +
diff --git a/src/components/ProxyPreviewBar.tsx b/src/components/ProxyPreviewBar.tsx index 9f6ac829..8029a40b 100644 --- a/src/components/ProxyPreviewBar.tsx +++ b/src/components/ProxyPreviewBar.tsx @@ -1,3 +1,4 @@ +import { createMemo } from 'solid-js' import { twMerge } from 'tailwind-merge' import Delay from '~/components/Delay' import { DELAY } from '~/config/enum' @@ -5,18 +6,32 @@ import { useProxies } from '~/signals/proxies' export default (props: { proxyNameList: string[]; now?: string }) => { const { proxyNodeMap } = useProxies() - const allNodesDelay = props.proxyNameList.map((i) => proxyNodeMap()[i].delay!) - const all = allNodesDelay.length - const good = allNodesDelay.filter( - (delay) => delay > DELAY.NOT_CONNECTED && delay <= DELAY.MEDIUM, - ).length - const middle = allNodesDelay.filter( - (delay) => delay > DELAY.MEDIUM && delay <= DELAY.HIGH, - ).length - const slow = allNodesDelay.filter((delay) => delay > DELAY.HIGH).length - const notConnected = allNodesDelay.filter( - (delay) => delay === DELAY.NOT_CONNECTED || typeof delay !== 'number', - ).length + const delayList = createMemo(() => + props.proxyNameList.map((i) => proxyNodeMap()[i].delay!), + ) + const all = createMemo(() => delayList().length) + const good = createMemo( + () => + delayList().filter( + (delay) => delay > DELAY.NOT_CONNECTED && delay <= DELAY.MEDIUM, + ).length, + ) + const middle = createMemo( + () => + delayList().filter((delay) => delay > DELAY.MEDIUM && delay <= DELAY.HIGH) + .length, + ) + const slow = createMemo( + () => delayList().filter((delay) => delay > DELAY.HIGH).length, + ) + const notConnected = createMemo( + () => + delayList().filter( + (delay) => delay === DELAY.NOT_CONNECTED || typeof delay !== 'number', + ).length, + ) + + console.log(good()) return (
@@ -24,30 +39,30 @@ export default (props: { proxyNameList: string[]; now?: string }) => {
-
- +
+
)