mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-12-26 07:24:10 +08:00
fix: bar and delay reactive
This commit is contained in:
parent
5952425621
commit
9ed05401a8
@ -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 <span class={textClassName}>{delay}ms</span>
|
||||
return (
|
||||
<>
|
||||
<Show
|
||||
when={typeof delay() === 'number' && delay() !== DELAY.NOT_CONNECTED}
|
||||
>
|
||||
<span class={textClassName()}>{delay()}ms</span>
|
||||
</Show>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Delay
|
||||
|
@ -44,7 +44,7 @@ export default (props: {
|
||||
{proxyNode()?.udp && ' :: udp'}
|
||||
</div>
|
||||
<div class="text-xs">
|
||||
<Delay delay={proxyNode()?.delay} />
|
||||
<Delay name={props.proxyName} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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 (
|
||||
<div class="flex w-full items-center">
|
||||
@ -24,30 +39,30 @@ export default (props: { proxyNameList: string[]; now?: string }) => {
|
||||
<div
|
||||
class={twMerge('h-2 bg-success')}
|
||||
style={{
|
||||
width: `${(good * 100) / all}%`, // cant use tw class cause dynamic classname wont import
|
||||
width: `${(good() * 100) / all()}%`, // cant use tw class cause dynamic classname wont import
|
||||
}}
|
||||
></div>
|
||||
<div
|
||||
class={twMerge('h-2 bg-warning')}
|
||||
style={{
|
||||
width: `${(middle * 100) / all}%`,
|
||||
width: `${(middle() * 100) / all()}%`,
|
||||
}}
|
||||
></div>
|
||||
<div
|
||||
class={twMerge('h-2 bg-error')}
|
||||
style={{
|
||||
width: `${(slow * 100) / all}%`,
|
||||
width: `${(slow() * 100) / all()}%`,
|
||||
}}
|
||||
></div>
|
||||
<div
|
||||
class={twMerge('h-2 bg-neutral')}
|
||||
style={{
|
||||
width: `${(notConnected * 100) / all}%`,
|
||||
width: `${(notConnected() * 100) / all()}%`,
|
||||
}}
|
||||
></div>
|
||||
</div>
|
||||
<div class="ml-4 text-xs">
|
||||
<Delay delay={proxyNodeMap()[props.now!]?.delay} />
|
||||
<div class="ml-3 w-8 text-xs">
|
||||
<Delay name={props.now} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user