metacubexd/src/components/Delay.tsx

32 lines
797 B
TypeScript
Raw Normal View History

2023-09-02 12:34:23 +08:00
import { Show, createEffect, createMemo, createSignal } from 'solid-js'
import { DELAY } from '~/constants'
import { useProxies } from '~/signals'
2023-09-02 11:52:51 +08:00
export const Delay = (props: { name?: string }) => {
const { delayMap } = useProxies()
2023-09-02 12:34:23 +08:00
const [textClassName, setTextClassName] = createSignal('')
const delay = createMemo(() => {
return delayMap()[props.name!]
2023-09-02 12:34:23 +08:00
})
2023-09-02 11:52:51 +08:00
2023-09-02 12:34:23 +08:00
createEffect(() => {
setTextClassName('text-success')
2023-09-02 11:52:51 +08:00
2023-09-02 12:34:23 +08:00
if (delay() > DELAY.HIGH) {
setTextClassName('text-error')
} else if (delay() > DELAY.MEDIUM) {
setTextClassName('text-warning')
}
})
2023-09-02 11:52:51 +08:00
2023-09-02 12:34:23 +08:00
return (
<>
<Show
when={typeof delay() === 'number' && delay() !== DELAY.NOT_CONNECTED}
>
<span class={textClassName()}>{delay()}ms</span>
</Show>
</>
)
2023-09-02 11:52:51 +08:00
}