wangzhibo
2023-10-31 9da39812105bfc387db3b3b7c4896983e03d247d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { createMemo, Match, Show, Switch } from 'solid-js'
import { ProxyPreviewBar, ProxyPreviewDots } from '~/components'
import { PROXIES_PREVIEW_TYPE } from '~/constants'
import { proxiesPreviewType } from '~/signals'
 
export const ProxyNodePreview = (props: {
  proxyNameList: string[]
  now?: string
}) => {
  const off = () => proxiesPreviewType() === PROXIES_PREVIEW_TYPE.OFF
 
  const isSmallGroup = createMemo(() => props.proxyNameList.length <= 10)
 
  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 (
      type === PROXIES_PREVIEW_TYPE.DOTS ||
      (type === PROXIES_PREVIEW_TYPE.Auto && isSmallGroup())
    )
  })
 
  return (
    <Show when={!off()}>
      <Switch>
        <Match when={isShowBar()}>
          <ProxyPreviewBar
            proxyNameList={props.proxyNameList}
            now={props.now}
          />
        </Match>
 
        <Match when={isShowDots()}>
          <ProxyPreviewDots
            proxyNameList={props.proxyNameList}
            now={props.now}
          />
        </Match>
      </Switch>
    </Show>
  )
}