2023-09-21 23:58:06 +08:00
|
|
|
import { createMemo, Match, Show, Switch } from 'solid-js'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { ProxyPreviewBar, ProxyPreviewDots } from '~/components'
|
|
|
|
import { PROXIES_PREVIEW_TYPE } from '~/constants'
|
|
|
|
import { proxiesPreviewType } from '~/signals'
|
2023-09-02 11:52:51 +08:00
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const ProxyNodePreview = (props: {
|
|
|
|
proxyNameList: string[]
|
|
|
|
now?: string
|
|
|
|
}) => {
|
2023-09-03 02:41:13 +08:00
|
|
|
const off = () => proxiesPreviewType() === PROXIES_PREVIEW_TYPE.OFF
|
|
|
|
|
2023-09-21 23:58:06 +08:00
|
|
|
const isSmallGroup = createMemo(() => props.proxyNameList.length <= 10)
|
2023-09-03 02:41:13 +08:00
|
|
|
|
2023-09-02 14:25:22 +08:00
|
|
|
const isShowBar = createMemo(() => {
|
|
|
|
const type = proxiesPreviewType()
|
|
|
|
|
|
|
|
return (
|
|
|
|
type === PROXIES_PREVIEW_TYPE.BAR ||
|
|
|
|
(type === PROXIES_PREVIEW_TYPE.Auto && !isSmallGroup())
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
const isShowDots = createMemo(() => {
|
|
|
|
const type = proxiesPreviewType()
|
|
|
|
|
|
|
|
return (
|
2023-09-02 14:28:01 +08:00
|
|
|
type === PROXIES_PREVIEW_TYPE.DOTS ||
|
2023-09-02 14:25:22 +08:00
|
|
|
(type === PROXIES_PREVIEW_TYPE.Auto && isSmallGroup())
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-09-02 11:52:51 +08:00
|
|
|
return (
|
2023-09-03 02:41:13 +08:00
|
|
|
<Show when={!off()}>
|
2023-09-21 23:58:06 +08:00
|
|
|
<Switch>
|
|
|
|
<Match when={isShowBar()}>
|
|
|
|
<ProxyPreviewBar
|
|
|
|
proxyNameList={props.proxyNameList}
|
|
|
|
now={props.now}
|
|
|
|
/>
|
|
|
|
</Match>
|
|
|
|
|
|
|
|
<Match when={isShowDots()}>
|
|
|
|
<ProxyPreviewDots
|
|
|
|
proxyNameList={props.proxyNameList}
|
|
|
|
now={props.now}
|
|
|
|
/>
|
|
|
|
</Match>
|
|
|
|
</Switch>
|
2023-09-03 02:41:13 +08:00
|
|
|
</Show>
|
2023-09-02 11:52:51 +08:00
|
|
|
)
|
|
|
|
}
|