From 20978b12b058bac0f53f1093ff9cebac7b4d3fcf Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Tue, 28 Feb 2023 13:20:50 +0800 Subject: [PATCH] Feature: add meanDelay display --- .../Proxies/components/Proxy/index.tsx | 15 +-- src/containers/Settings/index.tsx | 2 +- src/lib/request.ts | 1 + src/models/Proxy.ts | 106 ------------------ src/models/index.ts | 1 - 5 files changed, 10 insertions(+), 115 deletions(-) delete mode 100644 src/models/Proxy.ts diff --git a/src/containers/Proxies/components/Proxy/index.tsx b/src/containers/Proxies/components/Proxy/index.tsx index 3e1492e..7d7ba8f 100644 --- a/src/containers/Proxies/components/Proxy/index.tsx +++ b/src/containers/Proxies/components/Proxy/index.tsx @@ -49,10 +49,11 @@ export function Proxy (props: ProxyProps) { }) }, [config.name, getDelay, set]) - const delay = useMemo( - () => config.history?.length ? config.history.slice(-1)[0].delay : 0, - [config], - ) + const delay = config.history?.length ? config.history.slice(-1)[0].delay : 0 + const meanDelay = config.history?.length ? config.history.slice(-1)[0].meanDelay : undefined + + const delayText = delay === 0 ? '-' : `${delay}ms` + const meanDelayText = meanDelay === undefined || meanDelay === 0 ? '' : `(${meanDelay}ms)` useLayoutEffect(() => { const handler = () => { speedTest() } @@ -63,9 +64,9 @@ export function Proxy (props: ProxyProps) { const hasError = useMemo(() => delay === 0, [delay]) const color = useMemo( () => Object.keys(TagColors).find( - threshold => delay <= TagColors[threshold as keyof typeof TagColors], + threshold => (meanDelay ?? delay) <= TagColors[threshold as keyof typeof TagColors], ), - [delay], + [delay, meanDelay], ) const backgroundColor = hasError ? '#E5E7EB' : color @@ -80,7 +81,7 @@ export function Proxy (props: ProxyProps) {
{config.name}
{delay === 0 ? '-' : `${delay}ms`}
+{delayText}{meanDelayText}
{ config.udp &&UDP
}