diff --git a/src/hooks/useTSRemoteApp.tsx b/src/hooks/useTSRemoteApp.tsx index d80f0fe..5bd2c86 100644 --- a/src/hooks/useTSRemoteApp.tsx +++ b/src/hooks/useTSRemoteApp.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import { TS5ConnectionHandler } from "@/handlers/teamspeak/connectionHandler"; import { IClient, IChannel, IConnection, ITS5ConnectionHandler } from "@/interfaces/teamspeak"; import { useEffect, useState } from "react"; @@ -12,23 +13,6 @@ export default function useTSRemoteApp({ remoteAppPort = 5899 }: { remoteAppPort const [currentChannel, setCurrentChannel] = useState(undefined); const [currentClient, setCurrentClient] = useState(undefined); - function setCurrentStates() { - const currentConnection = connections.find((connection) => connection.id === activeConnectionId); - setCurrentConnection(currentConnection); - - if (currentConnection) { - const currentClient = clients.find((client) => client.id === currentConnection.clientId); - setCurrentClient(currentClient); - if (currentClient) { - const currentChannel = channels.find((channel) => channel.id === currentClient.channel?.id); - setCurrentChannel(currentChannel); - if (currentChannel) { - return currentChannel; - } - } - } - } - useEffect(() => { const tsConnection: ITS5ConnectionHandler = new TS5ConnectionHandler( remoteAppPort, @@ -41,7 +25,17 @@ export default function useTSRemoteApp({ remoteAppPort = 5899 }: { remoteAppPort }, []); useEffect(() => { - setCurrentStates(); + const currentConnection = connections.find((connection) => connection.id === activeConnectionId); + setCurrentConnection(currentConnection); + + if (currentConnection) { + const currentClient = clients.find((client) => client.id === currentConnection.clientId); + setCurrentClient(currentClient); + if (currentClient) { + const currentChannel = channels.find((channel) => channel.id === currentClient.channel?.id); + setCurrentChannel(currentChannel); + } + } }, [clients, channels, connections, activeConnectionId]); return {