48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import React, { useEffect, useRef, useState } from 'react';
|
|
import './App.scss';
|
|
import { ClientView } from './components/ClientView/ClientView';
|
|
import { ConnectionForm } from './components/ConnectionForm/ConnectionForm';
|
|
import { IRCManager } from './lib/irc-manager';
|
|
|
|
function App() {
|
|
const manager = useRef<IRCManager>();
|
|
const [initScreen, setInitScreen] = useState(true);
|
|
|
|
useEffect(() => {
|
|
manager.current = new IRCManager();
|
|
manager.current.on('connectionRemoved', () => {
|
|
if (!manager.current?.connections.length) {
|
|
setInitScreen(true);
|
|
}
|
|
});
|
|
manager.current.on('connectionAdded', () => {
|
|
setInitScreen(false);
|
|
});
|
|
}, []);
|
|
|
|
return (
|
|
<div className="App">
|
|
<main>
|
|
{initScreen ? (
|
|
<ConnectionForm
|
|
onSubmit={(nick, channel, host, ssl, port, password) => {
|
|
manager.current?.createNewConnection(
|
|
nick,
|
|
channel.split(','),
|
|
host,
|
|
ssl,
|
|
port,
|
|
password,
|
|
);
|
|
}}
|
|
/>
|
|
) : (
|
|
<>{manager.current && <ClientView manager={manager.current} />}</>
|
|
)}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default App;
|