diff --git a/src/components/Collpase.tsx b/src/components/Collpase.tsx index 55858ff..65edfea 100644 --- a/src/components/Collpase.tsx +++ b/src/components/Collpase.tsx @@ -1,5 +1,6 @@ import { JSX, ParentComponent } from 'solid-js' import { twMerge } from 'tailwind-merge' +// import { Ch} from '@tabler/icons-solidjs' type Props = { title: JSX.Element @@ -31,7 +32,7 @@ const Collapse: ParentComponent = (props) => { )} >
onCollapse(!props.isOpen)} > {title} diff --git a/src/components/ProxyNodeCard.tsx b/src/components/ProxyNodeCard.tsx index 2bdb33f..00ae483 100644 --- a/src/components/ProxyNodeCard.tsx +++ b/src/components/ProxyNodeCard.tsx @@ -1,6 +1,7 @@ import { createMemo } from 'solid-js' import { twMerge } from 'tailwind-merge' import { useProxies } from '~/signals/proxies' +import { getClassNameByDelay } from '~/utils/proxies' export default (props: { proxyName: string @@ -16,13 +17,8 @@ export default (props: { return '' } - let textClassName = 'text-green-500' - - if (delay > 500) { - textClassName = 'text-red-500' - } else if (delay > 200) { - textClassName = 'text-yellow-500' - } + const color = getClassNameByDelay(delay) + const textClassName = `text-${color}` return {delay}ms } diff --git a/src/components/ProxyNodeDots.tsx b/src/components/ProxyNodeDots.tsx new file mode 100644 index 0000000..cb684cb --- /dev/null +++ b/src/components/ProxyNodeDots.tsx @@ -0,0 +1,33 @@ +import { For } from 'solid-js' +import { twMerge } from 'tailwind-merge' +import { useProxies } from '~/signals/proxies' +import { getClassNameByDelay } from '~/utils/proxies' + +const Delay = (p: { delay: number | undefined; selected: boolean }) => { + const color = getClassNameByDelay(p.delay) + const bgClassName = `bg-${color}` + const isSelected = p.selected && `border-2 border-primary` + + 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/pages/Proxies.tsx b/src/pages/Proxies.tsx index a3e8b83..f06ded1 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -2,10 +2,11 @@ import { IconBrandSpeedtest, IconReload } from '@tabler/icons-solidjs' import { For, Show, createSignal, onMount } from 'solid-js' import Collapse from '~/components/Collpase' import ProxyNodeCard from '~/components/ProxyNodeCard' +import ProxyNodeDots from '~/components/ProxyNodeDots' import SubscriptionInfo from '~/components/SubscriptionInfo' import { useProxies } from '~/signals/proxies' import type { Proxy } from '~/types' -import { formatTimeFromNow } from '~/utils/date' +import { formatTimeFromNow } from '~/utils/proxies' export default () => { const { @@ -66,22 +67,26 @@ export default () => { {(proxy) => { const title = ( -
-
+ <> +
{proxy.name} - -
- {proxy.type} :: {proxy.now} -
+
- - -
+
+ {proxy.type} :: {proxy.now} +
+ + + + ) const content = ( @@ -123,35 +128,45 @@ export default () => { {(proxyProvider) => { const title = ( -
-
+ <> +
{proxyProvider.name} - -
- {proxyProvider.vehicleType} :: Updated{' '} - {formatTimeFromNow(proxyProvider.updatedAt)} +
+ +
- -
- - + +
+ {proxyProvider.vehicleType} :: Updated{' '} + {formatTimeFromNow(proxyProvider.updatedAt)}
-
+ + i.name) ?? [] + } + /> + + ) const content = ( diff --git a/src/utils/date.ts b/src/utils/date.ts deleted file mode 100644 index 519ecd9..0000000 --- a/src/utils/date.ts +++ /dev/null @@ -1,8 +0,0 @@ -import dayjs from 'dayjs' -import relativeTime from 'dayjs/plugin/relativeTime' - -dayjs.extend(relativeTime) - -export function formatTimeFromNow(time: number | string) { - return dayjs(time).fromNow() -} diff --git a/src/utils/proxies.ts b/src/utils/proxies.ts new file mode 100644 index 0000000..3b9acfb --- /dev/null +++ b/src/utils/proxies.ts @@ -0,0 +1,22 @@ +import dayjs from 'dayjs' +import relativeTime from 'dayjs/plugin/relativeTime' + +dayjs.extend(relativeTime) + +export function formatTimeFromNow(time: number | string) { + return dayjs(time).fromNow() +} + +export function getClassNameByDelay(delay: number | undefined) { + let name = 'green-500' + + if (typeof delay !== 'number' || delay === 0) { + name = 'base-100' + } else if (delay > 500) { + name = 'red-500' + } else if (delay > 200) { + name = 'yellow-500' + } + + return name +}