Add functionality to "Join Lobby" button
parent
c75b3ef1c2
commit
88627bb9a7
|
|
@ -1,4 +1,11 @@
|
||||||
|
import { Socket } from "socket.io-client";
|
||||||
|
import { ClientEvent } from "./ClientEvent";
|
||||||
|
|
||||||
export type JoinLobbyEvent = {
|
export type JoinLobbyEvent = {
|
||||||
userName: string;
|
userName: string;
|
||||||
lobbyId: string;
|
lobbyId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function handleJoinLobby(socket: Socket, payload: JoinLobbyEvent): void {
|
||||||
|
socket.emit(ClientEvent.JOIN_LOBBY, payload);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
import { CreateLobbyEvent, handleCreateLobby } from "interface";
|
import {
|
||||||
|
CreateLobbyEvent,
|
||||||
|
handleCreateLobby,
|
||||||
|
handleJoinLobby,
|
||||||
|
JoinLobbyEvent,
|
||||||
|
} from "interface";
|
||||||
import React, { ChangeEvent } from "react";
|
import React, { ChangeEvent } from "react";
|
||||||
import { Socket } from "socket.io-client";
|
import { Socket } from "socket.io-client";
|
||||||
|
|
||||||
|
|
@ -6,8 +11,13 @@ const LandingPage = (props: { socket: Socket }) => {
|
||||||
const socket = props.socket;
|
const socket = props.socket;
|
||||||
|
|
||||||
const createLobbyPayload: CreateLobbyEvent = { userName: "" };
|
const createLobbyPayload: CreateLobbyEvent = { userName: "" };
|
||||||
const registerUsername = (event: ChangeEvent<HTMLInputElement>) =>
|
const joinLobbyPayload: JoinLobbyEvent = { userName: "", lobbyId: "" };
|
||||||
(createLobbyPayload.userName = event.target.value);
|
const registerUsername = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
createLobbyPayload.userName = event.target.value;
|
||||||
|
joinLobbyPayload.userName = event.target.value;
|
||||||
|
};
|
||||||
|
const registerLobbyId = (event: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
(joinLobbyPayload.lobbyId = event.target.value);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
|
@ -23,8 +33,17 @@ const LandingPage = (props: { socket: Socket }) => {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="JoinLobby">
|
<div className="JoinLobby">
|
||||||
<input className="LobbyIdInput" placeholder="Enter Lobby Id"></input>
|
<input
|
||||||
<button className="JoinLobbyButton secondary">Join Lobby</button>
|
className="LobbyIdInput"
|
||||||
|
placeholder="Enter Lobby Id"
|
||||||
|
onChange={registerLobbyId}
|
||||||
|
></input>
|
||||||
|
<button
|
||||||
|
className="JoinLobbyButton secondary"
|
||||||
|
onClick={() => handleJoinLobby(socket, joinLobbyPayload)}
|
||||||
|
>
|
||||||
|
Join Lobby
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue