2023-09-02 12:34:23 +08:00
|
|
|
import { Show, createEffect, createMemo, createSignal } from 'solid-js'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { DELAY } from '~/constants'
|
|
|
|
import { useProxies } from '~/signals'
|
2023-09-02 11:52:51 +08:00
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const Delay = (props: { name?: string }) => {
|
2023-09-02 15:00:13 +08:00
|
|
|
const { delayMap } = useProxies()
|
2023-09-02 12:34:23 +08:00
|
|
|
const [textClassName, setTextClassName] = createSignal('')
|
|
|
|
const delay = createMemo(() => {
|
2023-09-02 15:00:13 +08:00
|
|
|
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
|
|
|
}
|