From a5034ef576516d705cc946c3b34866b3a367d620 Mon Sep 17 00:00:00 2001 From: nicola Date: Mon, 16 Mar 2020 21:31:08 +1100 Subject: [PATCH] Add simple routes to page co-authored-by: mitchemmc --- package.json | 1 + src/App.js | 81 +++++++--------------------------------------- src/routes/Game.js | 8 +++++ src/routes/Home.js | 8 +++++ src/routes/Join.js | 8 +++++ yarn.lock | 5 +++ 6 files changed, 42 insertions(+), 69 deletions(-) create mode 100644 src/routes/Game.js create mode 100644 src/routes/Home.js create mode 100644 src/routes/Join.js diff --git a/package.json b/package.json index 009d92d..7ceea07 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", + "hookrouter": "^1.2.3", "peerjs": "^1.2.0", "react": "^16.13.0", "react-dom": "^16.13.0", diff --git a/src/App.js b/src/App.js index a24a0be..e0beefd 100644 --- a/src/App.js +++ b/src/App.js @@ -1,80 +1,23 @@ import React, { useState, useRef } from "react"; +import { useRoutes } from "hookrouter"; +import { ThemeProvider } from "theme-ui"; -import { - ThemeProvider, - Box, - Heading, - Text, - Label, - Input, - Button -} from "theme-ui"; import theme from "./theme.js"; +import Home from "./routes/Home"; +import Game from "./routes/Game"; +import Join from "./routes/Join"; -import useSession from "./useSession"; +const routes = { + "/": () => , + "/game": () => , + "/join": () => +}; function App() { - const [connectId, setConnectId] = useState(""); - const connectToId = () => { - const connection = peer.connect(connectId); - connection.on("open", () => { - connection.on("data", data => { - const blob = new Blob([data]); - imgRef.current = blob; - setImgSrc(URL.createObjectURL(imgRef.current)); - }); - }); - }; - - const [imgSrc, setImgSrc] = useState(""); - const imgRef = useRef(null); - const loadImage = e => { - imgRef.current = e.target.files[0]; - setImgSrc(URL.createObjectURL(imgRef.current)); - for (let connection of Object.values(connections)) { - connection.send(imgRef.current); - } - }; - - const [peer, peerId, connections] = useSession(imgRef); - + const route = useRoutes(routes); return ( - - Your ID - {peerId} - - - - - - - - { - e.preventDefault(); - connectToId(); - }} - py={3} - > - - setConnectId(e.target.value)} - /> - - - + {route} ); } diff --git a/src/routes/Game.js b/src/routes/Game.js new file mode 100644 index 0000000..1786449 --- /dev/null +++ b/src/routes/Game.js @@ -0,0 +1,8 @@ +import React from "react"; +import { A } from "hookrouter"; + +function Game() { + return +} + +export default Game; \ No newline at end of file diff --git a/src/routes/Home.js b/src/routes/Home.js new file mode 100644 index 0000000..237968f --- /dev/null +++ b/src/routes/Home.js @@ -0,0 +1,8 @@ +import React from "react"; +import { A } from "hookrouter"; + +function Home() { + return +} + +export default Home; \ No newline at end of file diff --git a/src/routes/Join.js b/src/routes/Join.js new file mode 100644 index 0000000..d87c95b --- /dev/null +++ b/src/routes/Join.js @@ -0,0 +1,8 @@ +import React from "react"; +import { A } from "hookrouter"; + +function Join() { + return +} + +export default Join; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 2a58d8f..19a8086 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5136,6 +5136,11 @@ hmac-drbg@^1.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" +hookrouter@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/hookrouter/-/hookrouter-1.2.3.tgz#a65599a1be376b51734caf7c4f7f8aba59bb2c77" + integrity sha512-n0mqEBGgXIxYRNMHlwCzoyTOk0OB5Es3jwUyA3+2l5nte/52n0CMMj1bmoCabC8K43YTUEr0zzexTBfo//tq2Q== + hosted-git-info@^2.1.4: version "2.8.5" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.5.tgz#759cfcf2c4d156ade59b0b2dfabddc42a6b9c70c"