From 4d29e7c16e64278f2172af4e00b34cf4b10a50ee Mon Sep 17 00:00:00 2001 From: Zephyruso <127948745+Zephyruso@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:52:51 +0800 Subject: [PATCH] feat: preview by bar --- src/components/Delay.tsx | 21 +++++++ src/components/ProxyNodeCard.tsx | 22 ++----- src/components/ProxyNodeDots.tsx | 41 ------------- src/components/ProxyNodePreview.tsx | 92 +++++++++++++++++++++++++++++ src/config/enum.ts | 5 ++ src/config/user | 0 src/pages/Config.tsx | 39 ++++++++++++ src/pages/Proxies.tsx | 6 +- 8 files changed, 164 insertions(+), 62 deletions(-) create mode 100644 src/components/Delay.tsx delete mode 100644 src/components/ProxyNodeDots.tsx create mode 100644 src/components/ProxyNodePreview.tsx create mode 100644 src/config/user diff --git a/src/components/Delay.tsx b/src/components/Delay.tsx new file mode 100644 index 0000000..014b1de --- /dev/null +++ b/src/components/Delay.tsx @@ -0,0 +1,21 @@ +import { DELAY } from '~/config/enum' + +const Delay = (props: { delay: number | undefined }) => { + const delay = props.delay + + if (typeof delay !== 'number' || delay === DELAY.NOT_CONNECTED) { + return '' + } + + let textClassName = 'text-success' + + if (delay > DELAY.HIGH) { + textClassName = 'text-error' + } else if (delay > DELAY.MEDIUM) { + textClassName = 'text-warning' + } + + return {delay}ms +} + +export default Delay diff --git a/src/components/ProxyNodeCard.tsx b/src/components/ProxyNodeCard.tsx index cfd8deb..e671c63 100644 --- a/src/components/ProxyNodeCard.tsx +++ b/src/components/ProxyNodeCard.tsx @@ -1,6 +1,6 @@ import { createMemo } from 'solid-js' import { twMerge } from 'tailwind-merge' -import { DELAY } from '~/config/enum' +import Delay from '~/components/Delay' import { useProxies } from '~/signals/proxies' export default (props: { @@ -12,22 +12,6 @@ export default (props: { const { proxyNodeMap } = useProxies() const proxyNode = createMemo(() => proxyNodeMap()[proxyName]) - const Delay = (delay: number | undefined) => { - if (typeof delay !== 'number' || delay === DELAY.NOT_CONNECTED) { - return '' - } - - let textClassName = 'text-success' - - if (delay > DELAY.HIGH) { - textClassName = 'text-error' - } else if (delay > DELAY.MEDIUM) { - textClassName = 'text-warning' - } - - return {delay}ms - } - const formatProxyType = (type = '') => { const t = type.toLowerCase() @@ -59,7 +43,9 @@ export default (props: { {formatProxyType(proxyNode()?.type)} {proxyNode()?.udp && ' :: udp'} -
{Delay(proxyNode()?.delay)}
+
+ +
) diff --git a/src/components/ProxyNodeDots.tsx b/src/components/ProxyNodeDots.tsx deleted file mode 100644 index 1d0ea86..0000000 --- a/src/components/ProxyNodeDots.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { For } from 'solid-js' -import { twMerge } from 'tailwind-merge' -import { DELAY } from '~/config/enum' -import { useProxies } from '~/signals/proxies' - -const Delay = (p: { delay: number | undefined; selected: boolean }) => { - let dotClassName = p.selected - ? 'bg-white border-4 border-success' - : 'bg-success' - - if (typeof p.delay !== 'number' || p.delay === DELAY.NOT_CONNECTED) { - dotClassName = p.selected - ? 'bg-white border-4 border-neutral' - : 'bg-neutral' - } else if (p.delay > DELAY.HIGH) { - dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error' - } else if (p.delay > DELAY.MEDIUM) { - dotClassName = p.selected - ? 'bg-white border-4 border-warning' - : 'bg-warning' - } - - return
-} - -export default (props: { proxyNameList: string[]; now?: string }) => { - const { proxyNodeMap } = useProxies() - - return ( -
- proxyNodeMap()[name]!)}> - {(proxy) => { - const delay = proxy?.delay - const isSelected = props.now === proxy.name - - return - }} - -
- ) -} diff --git a/src/components/ProxyNodePreview.tsx b/src/components/ProxyNodePreview.tsx new file mode 100644 index 0000000..ec297b6 --- /dev/null +++ b/src/components/ProxyNodePreview.tsx @@ -0,0 +1,92 @@ +import { For, Show } from 'solid-js' +import { twMerge } from 'tailwind-merge' +import Delay from '~/components/Delay' +import { DELAY, PROXIES_PREVIEW_TYPE } from '~/config/enum' +import { proxiesPreviewType } from '~/pages/Config' +import { useProxies } from '~/signals/proxies' + +const DelayDots = (p: { delay: number | undefined; selected: boolean }) => { + let dotClassName = p.selected + ? 'bg-white border-4 border-success' + : 'bg-success' + + if (typeof p.delay !== 'number' || p.delay === DELAY.NOT_CONNECTED) { + dotClassName = p.selected + ? 'bg-white border-4 border-neutral' + : 'bg-neutral' + } else if (p.delay > DELAY.HIGH) { + dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error' + } else if (p.delay > DELAY.MEDIUM) { + dotClassName = p.selected + ? 'bg-white border-4 border-warning' + : 'bg-warning' + } + + return
+} + +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, + ).length + + return ( + <> + +
+
+
+
+
+
+
+
+ +
+
+
+ +
+ proxyNodeMap()[name]!)}> + {(proxy) => { + const delay = proxy?.delay + const isSelected = props.now === proxy.name + + return + }} + +
+
+ + ) +} diff --git a/src/config/enum.ts b/src/config/enum.ts index 47d46cd..0bcf46d 100644 --- a/src/config/enum.ts +++ b/src/config/enum.ts @@ -19,3 +19,8 @@ export enum DELAY { MEDIUM = 200, HIGH = 500, } + +export enum PROXIES_PREVIEW_TYPE { + DOTS = 'dots', + BAR = 'bar', +} diff --git a/src/config/user b/src/config/user new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index 45bab08..667838f 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -13,6 +13,17 @@ const schema = z.object({ 'mixed-port': z.number(), }) +import { makePersisted } from '@solid-primitives/storage' +import { PROXIES_PREVIEW_TYPE } from '~/config/enum' + +export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted( + createSignal(PROXIES_PREVIEW_TYPE.BAR), + { + name: 'proxiesPreviewType', + storage: localStorage, + }, +) + export default () => { const request = useRequest() @@ -94,6 +105,34 @@ export default () => { +
+
Proxies preview type:
+
+ + +
+
+
{(item) => ( diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index 7408a85..8cecc87 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -4,7 +4,7 @@ import { Show, createSignal, onMount } from 'solid-js' import Collapse from '~/components/Collpase' import ForTwoLine from '~/components/ForTwoLine' import ProxyCardGroups from '~/components/ProxyCardGroups' -import ProxyNodeDots from '~/components/ProxyNodeDots' +import ProxyNodePreview from '~/components/ProxyNodePreview' import SubscriptionInfo from '~/components/SubscriptionInfo' import { useProxies } from '~/signals/proxies' import type { Proxy } from '~/types' @@ -83,7 +83,7 @@ export default () => { {proxy.type} :: {proxy.now} - @@ -157,7 +157,7 @@ export default () => { - i.name) ?? [] }