titlehook for dynamic tab titles

This commit is contained in:
2023-03-15 15:04:04 +01:00
parent f1e3d4a790
commit c2095c8ae7
3 changed files with 26 additions and 6 deletions

View File

@@ -1,10 +1,14 @@
import React from "react";
import {GHButton} from "../components/Button";
import {Link} from "react-router-dom";
import useTitle from "../../utils/TitleHook";
const ROOM_URL = 'http://localhost:5062/room';
const Home = () => {
useTitle('Home');
const [rooms, setRooms] = React.useState<string[]>([]);
React.useEffect(() => {
@@ -21,17 +25,13 @@ const Home = () => {
});
}
const gotoRoom = (roomId: string) => {
window.location.href = `/room/${roomId}`;
}
return (
<div>
<GHButton onClick={handleCreateRoom}>Create Room</GHButton>
<ul>
{
rooms.map((room, index) => {
return <li key={index} onClick={() => gotoRoom(room)}>{room}</li>
return <li key={index}><Link to={`room/${room}`}>{room}</Link></li>
})
}
</ul>

View File

@@ -2,9 +2,12 @@ import useWebSocket from "react-use-websocket";
import React from "react";
import {useParams} from "react-router";
import {GHButton} from "../components/Button";
import useTitle from "../../utils/TitleHook";
const Room = () => {
useTitle('Mau!');
const {roomId} = useParams();
const WS_URL = `ws://localhost:5062/room/${roomId}`;
@@ -38,7 +41,10 @@ const Room = () => {
<div>
<h1>Room {roomId}</h1>
<GHButton onClick={handleLeaveRoom}>Leave Room</GHButton>
<form>
<form onSubmit={(event) => {
event.preventDefault();
handleSend();
}}>
<input type="text" name="message" placeholder="Send a message" value={message}
onChange={handleMessageChange}/>
<span onClick={handleSend}>Send</span>