Skip to content

Commit

Permalink
fix(proxies): latency widget
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Sep 2, 2023
1 parent b3c1bde commit b511b88
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
File renamed without changes.
24 changes: 11 additions & 13 deletions src/components/Latency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ export const Latency = (props: { name?: string }) => {
})

return (
<>
<Show
when={
typeof latency() === 'number' &&
latency() !== LATENCY_QUALITY_MAP_HTTP.NOT_CONNECTED
}
>
<span class={`whitespace-nowrap ${textClassName()}`}>
{latency()}
{t('ms')}
</span>
</Show>
</>
<Show
when={
typeof latency() === 'number' &&
latency() !== LATENCY_QUALITY_MAP_HTTP.NOT_CONNECTED
}
>
<span class={`whitespace-nowrap text-xs ${textClassName()}`}>
{latency()}
{t('ms')}
</span>
</Show>
)
}
8 changes: 4 additions & 4 deletions src/components/ProxyCardGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { createMemo, createSignal } from 'solid-js'
import { ProxyNodeCard } from '~/components'

export const ProxyCardGroups = (props: {
proxies: string[]
proxyNames: string[]
now?: string
onClick?: (name: string) => void
}) => {
const [maxRender, setMaxRender] = createSignal(100)
const proxies = createMemo(() => props.proxies.slice(0, maxRender()))
const proxyNames = createMemo(() => props.proxyNames.slice(0, maxRender()))

return (
<InfiniteScroll
each={proxies()}
hasMore={proxies().length < props.proxies.length}
each={proxyNames()}
hasMore={proxyNames().length < props.proxyNames.length}
next={() => setMaxRender(maxRender() + 30)}
>
{(proxy) => (
Expand Down
9 changes: 4 additions & 5 deletions src/components/ProxyPreviewBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ProxyPreviewBar = (props: {
}) => {
const { latencyMap } = useProxies()
const latencyList = createMemo(() =>
props.proxyNameList.map((i) => latencyMap()[i]),
props.proxyNameList.map((name) => latencyMap()[name]),
)
const all = createMemo(() => latencyList().length)
const good = createMemo(
Expand Down Expand Up @@ -42,7 +42,7 @@ export const ProxyPreviewBar = (props: {
)

return (
<div class="flex h-6 w-full items-center">
<div class="flex h-6 w-full items-center gap-2">
<div class="flex flex-1 overflow-hidden rounded-2xl">
<div
class="h-2 bg-success"
Expand All @@ -69,9 +69,8 @@ export const ProxyPreviewBar = (props: {
}}
></div>
</div>
<div class="ml-3 w-8 text-xs">
<Latency name={props.now} />
</div>

<Latency name={props.now} />
</div>
)
}
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './Button'
export * from './Collpase'
export * from './Collapse'
export * from './ConnectionsTableOrderingModal'
export * from './ForTwoColumns'
export * from './Header'
Expand Down
18 changes: 8 additions & 10 deletions src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default () => {
</h1>
<ForTwoColumns
subChild={proxies().map((proxy) => {
const sortedProxyNames = sortProxiesByOrderingType(
proxy.all ?? [],
latencyMap(),
proxiesOrderingType(),
)

const title = (
<>
<div class="mr-10 flex items-center justify-between">
Expand All @@ -61,11 +67,7 @@ export default () => {
</div>
<Show when={!collapsedMap()[`group-${proxy.name}`]}>
<ProxyNodePreview
proxyNameList={sortProxiesByOrderingType(
proxy.all ?? [],
latencyMap(),
proxiesOrderingType(),
)}
proxyNameList={sortedProxyNames}
now={proxy.now}
/>
</Show>
Expand All @@ -74,11 +76,7 @@ export default () => {

const content = (
<ProxyCardGroups
proxies={sortProxiesByOrderingType(
proxy.all ?? [],
latencyMap(),
proxiesOrderingType(),
)}
proxyNames={sortedProxyNames}
now={proxy.now}
onClick={(name) => {
onProxyNodeClick(proxy, name)
Expand Down
25 changes: 15 additions & 10 deletions src/pages/ProxyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import {
ProxyNodePreview,
SubscriptionInfo,
} from '~/components'
import { formatTimeFromNow, getBtnElFromClickEvent } from '~/helpers'
import { useProxies } from '~/signals'
import {
formatTimeFromNow,
getBtnElFromClickEvent,
sortProxiesByOrderingType,
} from '~/helpers'
import { proxiesOrderingType, useProxies } from '~/signals'

export default () => {
const [t] = useI18n()
Expand All @@ -19,6 +23,7 @@ export default () => {
updateProviderByProviderName,
updateAllProvider,
healthCheckByProviderName,
latencyMap,
} = useProxies()

const [collapsedMap, setCollapsedMap] = createSignal<Record<string, boolean>>(
Expand Down Expand Up @@ -66,6 +71,12 @@ export default () => {
</h1>
<ForTwoColumns
subChild={proxyProviders().map((proxyProvider) => {
const sortedProxyNames = sortProxiesByOrderingType(
proxyProvider.proxies.map((i) => i.name) ?? [],
latencyMap(),
proxiesOrderingType(),
)

const title = (
<>
<div class="mr-8 flex items-center justify-between">
Expand Down Expand Up @@ -96,18 +107,12 @@ export default () => {
{formatTimeFromNow(proxyProvider.updatedAt)}
</div>
<Show when={!collapsedMap()[`provider-${proxyProvider.name}`]}>
<ProxyNodePreview
proxyNameList={proxyProvider.proxies.map((i) => i.name) ?? []}
/>
<ProxyNodePreview proxyNameList={sortedProxyNames} />
</Show>
</>
)

const content = (
<ProxyCardGroups
proxies={proxyProvider.proxies.map((i) => i.name)}
/>
)
const content = <ProxyCardGroups proxyNames={sortedProxyNames} />

return (
<Collapse
Expand Down

0 comments on commit b511b88

Please sign in to comment.