metacubexd/src/components/ProxyNodePreview.tsx

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-09-02 14:25:22 +08:00
import { Show, createMemo } from 'solid-js'
2023-09-02 12:05:31 +08:00
import { PROXIES_PREVIEW_TYPE } from '~/config/enum'
import { proxiesPreviewType } from '~/signals/config'
2023-09-02 12:05:31 +08:00
import ProxyPreviewBar from './ProxyPreviewBar'
import ProxyPreviewDots from './ProxyPreviewDots'
2023-09-02 11:52:51 +08:00
export default (props: { proxyNameList: string[]; now?: string }) => {
2023-09-03 02:41:13 +08:00
const off = () => proxiesPreviewType() === PROXIES_PREVIEW_TYPE.OFF
2023-09-02 14:25:22 +08:00
const isSmallGroup = createMemo(() => props.proxyNameList.length <= 30)
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-02 14:25:22 +08:00
<Show when={isShowBar()}>
2023-09-02 12:05:31 +08:00
<ProxyPreviewBar proxyNameList={props.proxyNameList} now={props.now} />
2023-09-02 11:52:51 +08:00
</Show>
2023-09-02 14:25:22 +08:00
<Show when={isShowDots()}>
2023-09-02 12:05:31 +08:00
<ProxyPreviewDots proxyNameList={props.proxyNameList} now={props.now} />
2023-09-02 11:52:51 +08:00
</Show>
2023-09-03 02:41:13 +08:00
</Show>
2023-09-02 11:52:51 +08:00
)
}