refactor: use ws request conns

This commit is contained in:
Zephyruso 2023-09-08 18:42:15 +08:00
parent 6957cb4ddf
commit f2ef7790dd
2 changed files with 12 additions and 9 deletions

View File

@ -4,12 +4,16 @@ import { twMerge } from 'tailwind-merge'
import { Header } from '~/components'
import { ROUTES } from '~/constants'
import {
WsMsg,
curTheme,
endpoint,
selectedEndpoint,
setAllConnections,
setLatestConnectionMsg,
useAutoSwitchTheme,
useProxies,
useTwemoji,
useWsRequest,
} from '~/signals'
const Setup = lazy(() => import('~/pages/Setup'))
@ -28,6 +32,8 @@ export const App = () => {
createEffect(() => {
if (selectedEndpoint() && endpoint()) {
void useProxies().updateProxies()
setAllConnections([])
setLatestConnectionMsg(useWsRequest<WsMsg>('connections'))
}
})

View File

@ -1,9 +1,8 @@
import { differenceWith, isNumber, unionWith } from 'lodash'
import { Accessor, createEffect, createSignal, untrack } from 'solid-js'
import { Connection, ConnectionRawMessage } from '~/types'
import { selectedEndpoint, useWsRequest } from './request'
type WsMsg = {
export type WsMsg = {
connections: ConnectionRawMessage[]
uploadTotal: number
downloadTotal: number
@ -13,7 +12,8 @@ type WsMsg = {
// when user selects proxy and close some connections they can back and check connections
// they closed
let allConnections: Connection[] = []
const setAllConnections = (allConns: Connection[]) => {
export const setAllConnections = (allConns: Connection[]) => {
allConnections = allConns
}
@ -23,12 +23,9 @@ export let latestConnectionMsg: Accessor<WsMsg> = () => ({
connections: [],
})
createEffect(() => {
if (selectedEndpoint()) {
setAllConnections([])
latestConnectionMsg = useWsRequest<WsMsg>('connections')
}
})
export const setLatestConnectionMsg = (accessor: Accessor<WsMsg>) => {
latestConnectionMsg = accessor
}
export const useConnections = () => {
const [closedConnections, setClosedConnections] = createSignal<Connection[]>(