mirror of
https://github.com/DerTyp7/teamspeak-obs-overlay.git
synced 2025-10-29 12:52:09 +01:00
better readability
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user