fix(connections): ws error when switch end point

This commit is contained in:
Zephyruso 2023-09-08 11:35:53 +08:00
parent 15d20cde4a
commit b04b20f8f0

View File

@ -1,11 +1,5 @@
import { differenceWith, unionWith } from 'lodash' import { differenceWith, unionWith } from 'lodash'
import { import { Accessor, createEffect, createSignal, untrack } from 'solid-js'
createEffect,
createMemo,
createResource,
createSignal,
untrack,
} from 'solid-js'
import { Connection, ConnectionWithSpeed } from '~/types' import { Connection, ConnectionWithSpeed } from '~/types'
import { selectedEndpoint, useWsRequest } from './request' import { selectedEndpoint, useWsRequest } from './request'
@ -22,19 +16,17 @@ const [allConnectionsWithSpeed, setAllConnectionsWithSpeed] = createSignal<
ConnectionWithSpeed[] ConnectionWithSpeed[]
>([]) >([])
const [latestConnectionWsMessage] = createResource(async () => { export let connections: Accessor<WsMsg> = () => ({
await new Promise<void>((resolve) => { uploadTotal: 0,
createEffect(() => { downloadTotal: 0,
if (selectedEndpoint()) { connections: [],
resolve()
}
})
})
return useWsRequest<WsMsg>('connections')
}) })
export const connections = createMemo(() => latestConnectionWsMessage()?.()) createEffect(() => {
if (selectedEndpoint()) {
connections = useWsRequest<WsMsg>('connections')
}
})
export const useConnections = () => { export const useConnections = () => {
const [closedConnectionsWithSpeed, setClosedConnectionsWithSpeed] = const [closedConnectionsWithSpeed, setClosedConnectionsWithSpeed] =