From 510a0c5e707226a5281b8f356df539eee33f9291 Mon Sep 17 00:00:00 2001 From: GyDi Date: Sun, 29 Oct 2023 23:01:05 +0800 Subject: [PATCH] feat: adjust the delay display interval and color, close #836 --- src/components/proxy/proxy-item-mini.tsx | 10 ++-------- src/components/proxy/proxy-item.tsx | 10 ++-------- src/services/delay.ts | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/proxy/proxy-item-mini.tsx b/src/components/proxy/proxy-item-mini.tsx index aaf5ab1..c7e98bc 100644 --- a/src/components/proxy/proxy-item-mini.tsx +++ b/src/components/proxy/proxy-item-mini.tsx @@ -137,20 +137,14 @@ export const ProxyItemMini = (props: Props) => { e.stopPropagation(); onDelay(); }} - color={ - delay > 500 - ? "error.main" - : delay < 100 - ? "success.main" - : "text.secondary" - } + color={delayManager.formatDelayColor(delay)} sx={({ palette }) => !proxy.provider ? { ":hover": { bgcolor: alpha(palette.primary.main, 0.15) } } : {} } > - {delay > 1e5 ? "Error" : delay > 3000 ? "Timeout" : `${delay}`} + {delayManager.formatDelay(delay)} )} diff --git a/src/components/proxy/proxy-item.tsx b/src/components/proxy/proxy-item.tsx index c597112..d4c63c4 100644 --- a/src/components/proxy/proxy-item.tsx +++ b/src/components/proxy/proxy-item.tsx @@ -145,20 +145,14 @@ export const ProxyItem = (props: Props) => { e.stopPropagation(); onDelay(); }} - color={ - delay > 500 - ? "error.main" - : delay < 100 - ? "success.main" - : "text.secondary" - } + color={delayManager.formatDelayColor(delay)} sx={({ palette }) => !proxy.provider ? { ":hover": { bgcolor: alpha(palette.primary.main, 0.15) } } : {} } > - {delay > 1e5 ? "Error" : delay > 3000 ? "Timeout" : `${delay}ms`} + {delayManager.formatDelay(delay)} )} diff --git a/src/services/delay.ts b/src/services/delay.ts index 4739d1b..91e4ab8 100644 --- a/src/services/delay.ts +++ b/src/services/delay.ts @@ -107,6 +107,21 @@ class DelayManager { for (let i = 0; i < concurrency; ++i) help(); }); } + + formatDelay(delay: number) { + if (delay < 0) return "-"; + if (delay > 1e5) return "Error"; + if (delay >= 10000) return "Timeout"; // 10s + return `${delay}`; + } + + formatDelayColor(delay: number) { + if (delay <= 0) return "text.secondary"; + if (delay >= 10000) return "error.main"; + if (delay > 500) return "warning.main"; + if (delay > 100) return "text.secondary"; + return "success.main"; + } } export default new DelayManager();