Skip to content

Commit

Permalink
Merge pull request #43 from DerTyp7/refactor_custom-react-hook
Browse files Browse the repository at this point in the history
Refactor custom react hook
  • Loading branch information
DerTyp7 authored Jul 24, 2023
2 parents 0411265 + 8587271 commit b541edb
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 938 deletions.
245 changes: 231 additions & 14 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ts5-obs-overlay",
"private": true,
"version": "1.1.3",
"version": "1.2.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -15,6 +15,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1",
"react-ts5-remote-app-api": "^1.0.5",
"sass": "^1.63.6"
},
"devDependencies": {
Expand Down
51 changes: 4 additions & 47 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,14 @@
/* eslint-disable react-hooks/exhaustive-deps */
import "@styles/App.scss";
import { IChannel, IClient, IConnection, ITS5ConnectionHandler } from "@interfaces/teamspeak";
import { useEffect, useState } from "react";
import Viewer from "./Viewer";
import { useSearchParams } from "react-router-dom";
import { TS5ConnectionHandler } from "@handlers/teamspeak/connectionHandler";
import useTSRemoteApp, { IClient } from "react-ts5-remote-app-api";

export default function App() {
const [searchParams] = useSearchParams();

const [clients, setClients] = useState<IClient[]>([]);
const [channels, setChannels] = useState<IChannel[]>([]);
const [connections, setConnections] = useState<IConnection[]>([]);
const [activeConnectionId, setActiveConnectionId] = useState<number>(1);

const [currentConnection, setCurrentConnection] = useState<IConnection | undefined>(undefined);
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 remoteAppPort = searchParams.get("remoteAppPort");

console.log(searchParams.get("hideNonTalking"));
const tsConnection: ITS5ConnectionHandler = new TS5ConnectionHandler(
parseInt(remoteAppPort ?? "5899"),
setConnections,
setChannels,
setClients,
setActiveConnectionId
);
tsConnection.connect();
}, []);

useEffect(() => {
setCurrentStates();
}, [clients, channels, connections, activeConnectionId]);
const { clients, activeConnectionId, currentChannel } = useTSRemoteApp({
remoteAppPort: parseInt(searchParams.get("remoteAppPort") ?? "5899"),
});

return (
<div className="App">
Expand Down
2 changes: 1 addition & 1 deletion src/Viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IChannel, IClient } from "@interfaces/teamspeak";
import "@styles/Viewer.scss";
import { IChannel, IClient } from "react-ts5-remote-app-api";

export default function Viewer({
clients,
Expand Down
132 changes: 0 additions & 132 deletions src/handlers/teamspeak/connectionHandler.ts

This file was deleted.

Loading

0 comments on commit b541edb

Please sign in to comment.