From 9ed05401a891bf02af90541e08ec9358ada73cff Mon Sep 17 00:00:00 2001 From: Zephyruso <127948745+Zephyruso@users.noreply.github.com> Date: Sat, 2 Sep 2023 12:34:23 +0800 Subject: [PATCH] fix: bar and delay reactive --- src/components/Delay.tsx | 38 ++++++++++++++-------- src/components/ProxyNodeCard.tsx | 2 +- src/components/ProxyPreviewBar.tsx | 51 +++++++++++++++++++----------- 3 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/components/Delay.tsx b/src/components/Delay.tsx index 014b1de..999d8ce 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 e671c63..770a1b9 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 9f6ac82..8029a40 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 }) => {
-
- +
+
)