only poll tree if websocket connection is unavailable

This commit is contained in:
Athou
2023-09-12 20:14:17 +02:00
parent d7a3b75687
commit d633803ab5
3 changed files with 20 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
import { setWebSocketConnected } from "app/slices/server"
import { reloadTree } from "app/slices/tree"
import { useAppDispatch } from "app/store"
import { useEffect } from "react"
@@ -12,6 +13,8 @@ export const useWebSocket = () => {
const wsUrl = `${wsProtocol}://${currentUrl.hostname}:${currentUrl.port}/ws`
const ws = new WebsocketHeartbeatJs({ url: wsUrl, pingMsg: "ping" })
ws.onopen = () => dispatch(setWebSocketConnected(true))
ws.onclose = () => dispatch(setWebSocketConnected(false))
ws.onmessage = event => {
const { data } = event
if (typeof data === "string") {