|
@@ -1,4 +1,4 @@
|
|
-import React, { useState } from 'react';
|
|
|
|
|
|
+import React, { Fragment, useEffect, useState } from 'react';
|
|
import './css/App.css';
|
|
import './css/App.css';
|
|
import './css/fontawesome.css';
|
|
import './css/fontawesome.css';
|
|
import './css/solid.css';
|
|
import './css/solid.css';
|
|
@@ -7,20 +7,38 @@ import './css/main.css';
|
|
import useRoom from "./util/useRoom";
|
|
import useRoom from "./util/useRoom";
|
|
import ChooseRoom from "./components/ChooseRoom";
|
|
import ChooseRoom from "./components/ChooseRoom";
|
|
import Room from "./components/Room";
|
|
import Room from "./components/Room";
|
|
|
|
+import LoadingLogo from "./components/LoadingLogo";
|
|
|
|
+import NavBar from "./components/NavBar";
|
|
|
|
|
|
|
|
+function getPathFromUrl() {
|
|
|
|
+ return new URLSearchParams(window.location.search).get("room") || null
|
|
|
|
+}
|
|
|
|
|
|
-// const PATH = new URLSearchParams(window.location.search).get("room")
|
|
|
|
-// if (PATH === "" || PATH === undefined || PATH === null) {
|
|
|
|
-// window.location = "/";
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
|
|
+function App() {
|
|
|
|
+ const [path, setPath] = useState(getPathFromUrl());
|
|
|
|
+ const { room, setRoom, resolver, socket } = useRoom(path);
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ window.onpopstate = (_) => {
|
|
|
|
+ setPath(getPathFromUrl());
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
-function App() {
|
|
|
|
- const [path, setPath] = useState(null);
|
|
|
|
- const {room, setRoom, resolver, socket} = useRoom(path);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (path === null) {
|
|
|
|
+ const title = "ChuChube - Choose Room";
|
|
|
|
+ window.history.pushState({}, title, "/")
|
|
|
|
+ document.title = title;
|
|
|
|
+ } else {
|
|
|
|
+ const title = `ChuChube - ${path}`;
|
|
|
|
+ window.history.pushState({}, title, `player?room=${path}`)
|
|
|
|
+ document.title = title;
|
|
|
|
+ }
|
|
|
|
+ }, [path])
|
|
|
|
|
|
- if (socket.connected) {
|
|
|
|
|
|
+ if (path === null) {
|
|
|
|
+ return <ChooseRoom setPath={setPath}/>
|
|
|
|
+ } else if (socket.connected) {
|
|
return <Room room={room}
|
|
return <Room room={room}
|
|
setRoom={setRoom}
|
|
setRoom={setRoom}
|
|
exitRoom={() => setPath(null)}
|
|
exitRoom={() => setPath(null)}
|
|
@@ -28,7 +46,12 @@ function App() {
|
|
resolver={resolver}
|
|
resolver={resolver}
|
|
/>;
|
|
/>;
|
|
} else {
|
|
} else {
|
|
- return <ChooseRoom setPath={setPath}/>
|
|
|
|
|
|
+ return <Fragment>
|
|
|
|
+ <NavBar exitRoom={() => setPath(null)}/>
|
|
|
|
+ <div className="absoluteCenter" style={{height: "200px"}}>
|
|
|
|
+ <LoadingLogo/>
|
|
|
|
+ </div>
|
|
|
|
+ </Fragment>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|