mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 05:15:35 +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 { DELAY } from '~/config/enum'
|
||||||
|
import { useProxies } from '~/signals/proxies'
|
||||||
|
|
||||||
const Delay = (props: { delay: number | undefined }) => {
|
const Delay = (props: { name?: string }) => {
|
||||||
const delay = props.delay
|
const { proxyNodeMap } = useProxies()
|
||||||
|
const [textClassName, setTextClassName] = createSignal('')
|
||||||
|
const delay = createMemo(() => {
|
||||||
|
return proxyNodeMap()[props.name!]?.delay!
|
||||||
|
})
|
||||||
|
|
||||||
if (typeof delay !== 'number' || delay === DELAY.NOT_CONNECTED) {
|
createEffect(() => {
|
||||||
return ''
|
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) {
|
return (
|
||||||
textClassName = 'text-error'
|
<>
|
||||||
} else if (delay > DELAY.MEDIUM) {
|
<Show
|
||||||
textClassName = 'text-warning'
|
when={typeof delay() === 'number' && delay() !== DELAY.NOT_CONNECTED}
|
||||||
}
|
>
|
||||||
|
<span class={textClassName()}>{delay()}ms</span>
|
||||||
return <span class={textClassName}>{delay}ms</span>
|
</Show>
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Delay
|
export default Delay
|
||||||
|
@ -44,7 +44,7 @@ export default (props: {
|
|||||||
{proxyNode()?.udp && ' :: udp'}
|
{proxyNode()?.udp && ' :: udp'}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-xs">
|
<div class="text-xs">
|
||||||
<Delay delay={proxyNode()?.delay} />
|
<Delay name={props.proxyName} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { createMemo } from 'solid-js'
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
import Delay from '~/components/Delay'
|
import Delay from '~/components/Delay'
|
||||||
import { DELAY } from '~/config/enum'
|
import { DELAY } from '~/config/enum'
|
||||||
@ -5,18 +6,32 @@ import { useProxies } from '~/signals/proxies'
|
|||||||
|
|
||||||
export default (props: { proxyNameList: string[]; now?: string }) => {
|
export default (props: { proxyNameList: string[]; now?: string }) => {
|
||||||
const { proxyNodeMap } = useProxies()
|
const { proxyNodeMap } = useProxies()
|
||||||
const allNodesDelay = props.proxyNameList.map((i) => proxyNodeMap()[i].delay!)
|
const delayList = createMemo(() =>
|
||||||
const all = allNodesDelay.length
|
props.proxyNameList.map((i) => proxyNodeMap()[i].delay!),
|
||||||
const good = allNodesDelay.filter(
|
)
|
||||||
(delay) => delay > DELAY.NOT_CONNECTED && delay <= DELAY.MEDIUM,
|
const all = createMemo(() => delayList().length)
|
||||||
).length
|
const good = createMemo(
|
||||||
const middle = allNodesDelay.filter(
|
() =>
|
||||||
(delay) => delay > DELAY.MEDIUM && delay <= DELAY.HIGH,
|
delayList().filter(
|
||||||
).length
|
(delay) => delay > DELAY.NOT_CONNECTED && delay <= DELAY.MEDIUM,
|
||||||
const slow = allNodesDelay.filter((delay) => delay > DELAY.HIGH).length
|
).length,
|
||||||
const notConnected = allNodesDelay.filter(
|
)
|
||||||
(delay) => delay === DELAY.NOT_CONNECTED || typeof delay !== 'number',
|
const middle = createMemo(
|
||||||
).length
|
() =>
|
||||||
|
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 (
|
return (
|
||||||
<div class="flex w-full items-center">
|
<div class="flex w-full items-center">
|
||||||
@ -24,30 +39,30 @@ export default (props: { proxyNameList: string[]; now?: string }) => {
|
|||||||
<div
|
<div
|
||||||
class={twMerge('h-2 bg-success')}
|
class={twMerge('h-2 bg-success')}
|
||||||
style={{
|
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>
|
||||||
<div
|
<div
|
||||||
class={twMerge('h-2 bg-warning')}
|
class={twMerge('h-2 bg-warning')}
|
||||||
style={{
|
style={{
|
||||||
width: `${(middle * 100) / all}%`,
|
width: `${(middle() * 100) / all()}%`,
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
<div
|
<div
|
||||||
class={twMerge('h-2 bg-error')}
|
class={twMerge('h-2 bg-error')}
|
||||||
style={{
|
style={{
|
||||||
width: `${(slow * 100) / all}%`,
|
width: `${(slow() * 100) / all()}%`,
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
<div
|
<div
|
||||||
class={twMerge('h-2 bg-neutral')}
|
class={twMerge('h-2 bg-neutral')}
|
||||||
style={{
|
style={{
|
||||||
width: `${(notConnected * 100) / all}%`,
|
width: `${(notConnected() * 100) / all()}%`,
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-4 text-xs">
|
<div class="ml-3 w-8 text-xs">
|
||||||
<Delay delay={proxyNodeMap()[props.now!]?.delay} />
|
<Delay name={props.now} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user