Skip to content

Commit

Permalink
feat: relax https latency test range
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Sep 2, 2023
1 parent bbeb7c2 commit 1b09fa3
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 26 deletions.
File renamed without changes.
15 changes: 9 additions & 6 deletions src/components/Delay.tsx → src/components/Latency.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Show, createEffect, createMemo, createSignal } from 'solid-js'
import { DELAY } from '~/constants'
import { useProxies } from '~/signals'
import { LATENCY_QUALITY_MAP_HTTP } from '~/constants'
import { latencyQualityMap, useProxies } from '~/signals'

export const Delay = (props: { name?: string }) => {
export const Latency = (props: { name?: string }) => {
const { delayMap } = useProxies()
const [textClassName, setTextClassName] = createSignal('')
const delay = createMemo(() => {
Expand All @@ -12,17 +12,20 @@ export const Delay = (props: { name?: string }) => {
createEffect(() => {
setTextClassName('text-success')

if (delay() > DELAY.HIGH) {
if (delay() > latencyQualityMap().HIGH) {
setTextClassName('text-error')
} else if (delay() > DELAY.MEDIUM) {
} else if (delay() > latencyQualityMap().MEDIUM) {
setTextClassName('text-warning')
}
})

return (
<>
<Show
when={typeof delay() === 'number' && delay() !== DELAY.NOT_CONNECTED}
when={
typeof delay() === 'number' &&
delay() !== LATENCY_QUALITY_MAP_HTTP.NOT_CONNECTED
}
>
<span class={textClassName()}>{delay()}ms</span>
</Show>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProxyNodeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMemo } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Delay } from '~/components'
import { Latency } from '~/components'
import { useProxies } from '~/signals'

export default (props: {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default (props: {
{proxyNode()?.udp && ' :: udp'}
</div>
<div class="text-xs">
<Delay name={props.proxyName} />
<Latency name={props.proxyName} />
</div>
</div>
</div>
Expand Down
25 changes: 16 additions & 9 deletions src/components/ProxyPreviewBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createMemo } from 'solid-js'
import { Delay } from '~/components'
import { DELAY } from '~/constants'
import { useProxies } from '~/signals'
import { Latency } from '~/components'
import { latencyQualityMap, useProxies } from '~/signals'

export const ProxyPreviewBar = (props: {
proxyNameList: string[]
Expand All @@ -15,21 +14,29 @@ export const ProxyPreviewBar = (props: {
const good = createMemo(
() =>
delayList().filter(
(delay) => delay > DELAY.NOT_CONNECTED && delay <= DELAY.MEDIUM,
(delay) =>
delay > latencyQualityMap().NOT_CONNECTED &&
delay <= latencyQualityMap().MEDIUM,
).length,
)
const middle = createMemo(
() =>
delayList().filter((delay) => delay > DELAY.MEDIUM && delay <= DELAY.HIGH)
.length,
delayList().filter(
(delay) =>
delay > latencyQualityMap().NOT_CONNECTED &&
delay <= latencyQualityMap().HIGH,
).length,
)
const slow = createMemo(
() => delayList().filter((delay) => delay > DELAY.HIGH).length,
() =>
delayList().filter((delay) => delay > latencyQualityMap().HIGH).length,
)
const notConnected = createMemo(
() =>
delayList().filter(
(delay) => delay === DELAY.NOT_CONNECTED || typeof delay !== 'number',
(delay) =>
delay === latencyQualityMap().NOT_CONNECTED ||
typeof delay !== 'number',
).length,
)

Expand Down Expand Up @@ -62,7 +69,7 @@ export const ProxyPreviewBar = (props: {
></div>
</div>
<div class="ml-3 w-8 text-xs">
<Delay name={props.now} />
<Latency name={props.now} />
</div>
</div>
)
Expand Down
17 changes: 12 additions & 5 deletions src/components/ProxyPreviewDots.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { For } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { DELAY } from '~/constants'
import { useProxies } from '~/signals'
import {
LATENCY_QUALITY_MAP_HTTP,
LATENCY_QUALITY_MAP_HTTPS,
} from '~/constants'
import { isLatencyTestByHttps, useProxies } from '~/signals'

const DelayDots = (p: { delay: number | undefined; selected: boolean }) => {
const delayMap = isLatencyTestByHttps()
? LATENCY_QUALITY_MAP_HTTP
: LATENCY_QUALITY_MAP_HTTPS

let dotClassName = p.selected
? 'bg-white border-4 border-success'
: 'bg-success'

if (typeof p.delay !== 'number' || p.delay === DELAY.NOT_CONNECTED) {
if (typeof p.delay !== 'number' || p.delay === delayMap.NOT_CONNECTED) {
dotClassName = p.selected
? 'bg-white border-4 border-neutral'
: 'bg-neutral'
} else if (p.delay > DELAY.HIGH) {
} else if (p.delay > delayMap.HIGH) {
dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error'
} else if (p.delay > DELAY.MEDIUM) {
} else if (p.delay > delayMap.MEDIUM) {
dotClassName = p.selected
? 'bg-white border-4 border-warning'
: 'bg-warning'
Expand Down
4 changes: 2 additions & 2 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export * from './Button'
export * from './Collpase'
export * from './ConnectionsModal'
export * from './Delay'
export * from './ConnectionsTableOrderingModal'
export * from './ForTwoColumns'
export * from './Header'
export * from './Latency'
export * from './ProxyCardGroups'
export * from './ProxyNodeCard'
export * from './ProxyNodePreview'
Expand Down
8 changes: 7 additions & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ export enum ROUTES {
Config = '/config',
}

export enum DELAY {
export enum LATENCY_QUALITY_MAP_HTTP {
NOT_CONNECTED = 0,
MEDIUM = 200,
HIGH = 500,
}

export enum LATENCY_QUALITY_MAP_HTTPS {
NOT_CONNECTED = 0,
MEDIUM = 800,
HIGH = 1500,
}

export enum PROXIES_PREVIEW_TYPE {
OFF = 'off',
DOTS = 'dots',
Expand Down
12 changes: 11 additions & 1 deletion src/signals/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { makePersisted } from '@solid-primitives/storage'
import { createSignal } from 'solid-js'
import { PROXIES_PREVIEW_TYPE, PROXIES_SORTING_TYPE } from '~/constants'
import {
LATENCY_QUALITY_MAP_HTTP,
LATENCY_QUALITY_MAP_HTTPS,
PROXIES_PREVIEW_TYPE,
PROXIES_SORTING_TYPE,
} from '~/constants'
import { setCurTheme } from '~/signals'

export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted(
Expand Down Expand Up @@ -36,6 +41,11 @@ export const [renderInTwoColumn, setRenderInTwoColumn] = makePersisted(
{ name: 'renderInTwoColumn', storage: localStorage },
)

export const isLatencyTestByHttps = () => urlForDelayTest().startsWith('https')

export const latencyQualityMap = () =>
isLatencyTestByHttps() ? LATENCY_QUALITY_MAP_HTTPS : LATENCY_QUALITY_MAP_HTTP

const setTheme = (isDark: boolean) => {
if (autoSwitchTheme()) {
if (isDark) {
Expand Down

0 comments on commit 1b09fa3

Please sign in to comment.