fix: init scroll from 30 && revert delay map

This commit is contained in:
Zephyruso 2023-09-02 15:00:13 +08:00
parent 135111914d
commit c260db13df
6 changed files with 27 additions and 23 deletions

View File

@ -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(() => {

View File

@ -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 (

View File

@ -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(

View File

@ -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} />
}}

View File

@ -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>

View File

@ -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>>(
{},
)
@ -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 () => {
@ -72,10 +77,9 @@ export function useProxies() {
name: proxyName,
}),
})
proxyGroup.now = proxyName
setProxies(proxyGroupList)
updateProxy()
setTimeout(updateProxy)
}
const delayTestByProxyGroupName = async (proxyGroupName: string) => {
@ -88,14 +92,9 @@ export function useProxies() {
})
.json()
Object.entries(data).forEach(([name, delay]) => {
setProxyNodeMap({
...proxyNodeMap(),
[name]: {
...proxyNodeMap()[name],
delay: delay,
},
})
setDelayMap({
...delayMap(),
...data,
})
}
@ -115,6 +114,7 @@ export function useProxies() {
proxies,
proxyProviders,
delayTestByProxyGroupName,
delayMap,
proxyNodeMap,
updateProxy,
setProxyGroupByProxyName,