Skip to content

Commit

Permalink
fix: init scroll from 30 && revert delay map
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso authored and Zephyruso committed Sep 2, 2023
1 parent 1351119 commit c260db1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/components/Delay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { DELAY } from '~/config/enum'
import { useProxies } from '~/signals/proxies'

const Delay = (props: { name?: string }) => {
const { proxyNodeMap } = useProxies()
const { delayMap } = useProxies()
const [textClassName, setTextClassName] = createSignal('')
const delay = createMemo(() => {
return proxyNodeMap()[props.name!]?.delay!
return delayMap()[props.name!]
})

createEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProxyCardGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default (props: {
now?: string
onClick?: (name: string) => void
}) => {
const [maxRender, setMaxRender] = createSignal(30)
const [maxRender, setMaxRender] = createSignal(100)
const proxies = createMemo(() => props.proxies.slice(0, maxRender()))

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProxyPreviewBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { DELAY } from '~/config/enum'
import { useProxies } from '~/signals/proxies'

export default (props: { proxyNameList: string[]; now?: string }) => {
const { proxyNodeMap } = useProxies()
const { delayMap } = useProxies()
const delayList = createMemo(() =>
props.proxyNameList.map((i) => proxyNodeMap()[i].delay!),
props.proxyNameList.map((i) => delayMap()[i]),
)
const all = createMemo(() => delayList().length)
const good = createMemo(
Expand Down
14 changes: 9 additions & 5 deletions src/components/ProxyPreviewDots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ const DelayDots = (p: { delay: number | undefined; selected: boolean }) => {
}

export default (props: { proxyNameList: string[]; now?: string }) => {
const { proxyNodeMap } = useProxies()
const { delayMap } = useProxies()

return (
<div class="flex w-full flex-wrap items-center">
<For each={props.proxyNameList.map((name) => proxyNodeMap()[name]!)}>
{(proxy) => {
const delay = proxy?.delay
const isSelected = props.now === proxy.name
<For
each={props.proxyNameList.map((name): [string, number] => [
name,
delayMap()[name],
])}
>
{([name, delay]) => {
const isSelected = props.now === name

return <DelayDots delay={delay} selected={isSelected} />
}}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const CHART_MAX_XAXIS = 10

const TrafficWidget: ParentComponent<{ label: JSX.Element }> = (props) => (
<div class="stat flex-1">
<div class="stat-title text-secondary-content">{props.label}</div>
<div class="stat-title text-primary-content">{props.label}</div>
<div class="stat-value text-primary-content">
{children(() => props.children)()}
</div>
Expand Down
24 changes: 12 additions & 12 deletions src/signals/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ type ProxyInfo = {
name: string
udp: boolean
type: string
delay?: number
}
// these signals should be global state
const [proxies, setProxies] = createSignal<Proxy[]>([])
const [proxyProviders, setProxyProviders] = createSignal<ProxyProvider[]>([])

const [delayMap, setDelayMap] = createSignal<Record<string, number>>({})
const [proxyNodeMap, setProxyNodeMap] = createSignal<Record<string, ProxyInfo>>(
{},
)
Expand All @@ -20,15 +20,20 @@ export function useProxies() {
const request = useRequest()
const setProxyInfoByProixes = (proxies: Proxy[] | ProxyNode[]) => {
proxies.forEach((proxy) => {
const delay = proxy.history.at(-1)?.delay ?? 0

setProxyNodeMap({
...proxyNodeMap(),
[proxy.name]: {
udp: proxy.udp,
type: proxy.type,
delay: proxy.history.at(-1)?.delay ?? 0,
name: proxy.name,
},
})
setDelayMap({
...delayMap(),
[proxy.name]: delay,
})
})
}
const updateProxy = async () => {
Expand Down Expand Up @@ -72,10 +77,9 @@ export function useProxies() {
name: proxyName,
}),
})

proxyGroup.now = proxyName
setProxies(proxyGroupList)
updateProxy()
setTimeout(updateProxy)
}

const delayTestByProxyGroupName = async (proxyGroupName: string) => {
Expand All @@ -88,14 +92,9 @@ export function useProxies() {
})
.json()

Object.entries(data).forEach(([name, delay]) => {
setProxyNodeMap({
...proxyNodeMap(),
[name]: {
...proxyNodeMap()[name],
delay: delay,
},
})
setDelayMap({
...delayMap(),
...data,
})
}

Expand All @@ -115,6 +114,7 @@ export function useProxies() {
proxies,
proxyProviders,
delayTestByProxyGroupName,
delayMap,
proxyNodeMap,
updateProxy,
setProxyGroupByProxyName,
Expand Down

0 comments on commit c260db1

Please sign in to comment.