better readability

This commit is contained in:
Janis
2023-07-24 00:50:08 +02:00
parent da518bbd1e
commit 793ae71186

View File

@@ -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<IChannel | undefined>(undefined);
const [currentClient, setCurrentClient] = useState<IClient | undefined>(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 {