sass setup + stole github button css >:)
This commit is contained in:
13
src/layout/components/Button.tsx
Normal file
13
src/layout/components/Button.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import React, {FunctionComponent} from "react";
|
||||
|
||||
interface Props {
|
||||
className?: string
|
||||
onClick?: () => void
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
export const GHButton: FunctionComponent<Props> = ({className, onClick, children}) => {
|
||||
return (
|
||||
<span className={`gh-button ${className}`} onClick={onClick}>{children}</span>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import {GHButton} from "../components/Button";
|
||||
|
||||
const ROOM_URL = 'http://localhost:5062/room';
|
||||
|
||||
@@ -8,14 +9,8 @@ const Home = () => {
|
||||
|
||||
React.useEffect(() => {
|
||||
fetch(ROOM_URL)
|
||||
.then((r) => {
|
||||
console.log(r);
|
||||
return r.json();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log(data);
|
||||
setRooms(data);
|
||||
});
|
||||
.then(r => r.json())
|
||||
.then(data => setRooms(data));
|
||||
}, []);
|
||||
|
||||
const handleCreateRoom = () => {
|
||||
@@ -32,7 +27,7 @@ const Home = () => {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button onClick={handleCreateRoom}>Create Room</button>
|
||||
<GHButton onClick={handleCreateRoom}>Create Room</GHButton>
|
||||
<ul>
|
||||
{
|
||||
rooms.map((room, index) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useWebSocket from "react-use-websocket";
|
||||
import React from "react";
|
||||
import {useParams} from "react-router";
|
||||
import {GHButton} from "../components/Button";
|
||||
|
||||
const Room = () => {
|
||||
|
||||
@@ -29,9 +30,14 @@ const Room = () => {
|
||||
setMessage(event.target.value);
|
||||
}
|
||||
|
||||
const handleLeaveRoom = () => {
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Room {roomId}</h1>
|
||||
<GHButton onClick={handleLeaveRoom}>Leave Room</GHButton>
|
||||
<form>
|
||||
<input type="text" name="message" placeholder="Send a message" value={message}
|
||||
onChange={handleMessageChange}/>
|
||||
|
||||
Reference in New Issue
Block a user