Remove duplicate socket connection
parent
fae67ce2a2
commit
2191a2fdc4
|
|
@ -1,15 +1,17 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { io } from "socket.io-client";
|
import { Socket } from "socket.io-client";
|
||||||
import LandingPage from "./pages/landing/LandingPage";
|
import LandingPage from "./pages/landing/LandingPage";
|
||||||
|
|
||||||
function App() {
|
export interface AppProps {
|
||||||
const socket = io("http://localhost:3010");
|
socket: Socket;
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="App">
|
|
||||||
<LandingPage socket={socket} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const App = (props: AppProps) => {
|
||||||
|
return (
|
||||||
|
<div className="app">
|
||||||
|
<LandingPage {...props} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@ import React from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
import "./App.scss";
|
import "./App.scss";
|
||||||
|
import { io } from "socket.io-client";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(
|
const root = ReactDOM.createRoot(
|
||||||
document.getElementById("root") as HTMLElement,
|
document.getElementById("root") as HTMLElement,
|
||||||
);
|
);
|
||||||
|
const socket = io("http://localhost:3010");
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<App socket={socket} />
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,12 @@ import {
|
||||||
import React, { ChangeEvent } from "react";
|
import React, { ChangeEvent } from "react";
|
||||||
import { Socket } from "socket.io-client";
|
import { Socket } from "socket.io-client";
|
||||||
|
|
||||||
const LandingPage = (props: { socket: Socket }) => {
|
export interface LandingPageProps {
|
||||||
const socket = props.socket;
|
socket: Socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LandingPage = (props: LandingPageProps) => {
|
||||||
|
const { socket } = props;
|
||||||
|
|
||||||
const createLobbyPayload: CreateLobbyEvent = { userName: "" };
|
const createLobbyPayload: CreateLobbyEvent = { userName: "" };
|
||||||
const joinLobbyPayload: JoinLobbyEvent = { userName: "", lobbyId: "" };
|
const joinLobbyPayload: JoinLobbyEvent = { userName: "", lobbyId: "" };
|
||||||
|
|
@ -21,25 +25,25 @@ const LandingPage = (props: { socket: Socket }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<div className="LandingPageTitle">
|
<div className="landing-page-title">
|
||||||
<h1>Trains And Roads</h1>
|
<h1>Trains And Roads</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="UserNameImput">
|
<div className="user-name-input">
|
||||||
<input placeholder="Enter username" onChange={registerUsername}></input>
|
<input placeholder="Enter username" onChange={registerUsername}></input>
|
||||||
</div>
|
</div>
|
||||||
<div className="CreateLobbyButton">
|
<div className="create-lobby-button">
|
||||||
<button onClick={() => handleCreateLobby(socket, createLobbyPayload)}>
|
<button onClick={() => handleCreateLobby(socket, createLobbyPayload)}>
|
||||||
Create Lobby
|
Create Lobby
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="JoinLobby">
|
<div className="join-lobby">
|
||||||
<input
|
<input
|
||||||
className="LobbyIdInput"
|
className="lobby-id-input"
|
||||||
placeholder="Enter Lobby Id"
|
placeholder="Enter Lobby Id"
|
||||||
onChange={registerLobbyId}
|
onChange={registerLobbyId}
|
||||||
></input>
|
></input>
|
||||||
<button
|
<button
|
||||||
className="JoinLobbyButton secondary"
|
className="join-lobby-button secondary"
|
||||||
onClick={() => handleJoinLobby(socket, joinLobbyPayload)}
|
onClick={() => handleJoinLobby(socket, joinLobbyPayload)}
|
||||||
>
|
>
|
||||||
Join Lobby
|
Join Lobby
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue