|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useState, useRef } from 'react';
|
|
|
+import React, { useEffect, useRef, useState } from 'react';
|
|
|
import { CSSTransition } from 'react-transition-group';
|
|
|
import styles from './App.module.css';
|
|
|
import GamePanel from './components/screens/GamePanel';
|
|
@@ -8,8 +8,7 @@ import Lobby from './components/screens/Lobby';
|
|
|
import RoundSummary from './components/screens/RoundSummary';
|
|
|
import ApiInfo from './components/util/ApiInfo';
|
|
|
import { ERROR, IN_ROUND, POST_GAME, POST_ROUND, PRE_GAME, PRE_ROUND } from './domain/GameState';
|
|
|
-import { useGameState } from './domain/gameStore';
|
|
|
-import useDirectGameLinks from './hooks/useDirectGameLinks';
|
|
|
+import { dispatch, useGameState } from './domain/gameStore';
|
|
|
|
|
|
const needsHeaderFooter = {
|
|
|
[PRE_GAME]: true,
|
|
@@ -58,6 +57,11 @@ const Footer = ({ show }) => {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+const paramRouter = {
|
|
|
+ join: dispatch.goToLobby,
|
|
|
+ summary: gameId => dispatch.goToSummary(gameId, false),
|
|
|
+}
|
|
|
+
|
|
|
const State = ({ show, children, setTransitioning }) => {
|
|
|
const transitionRef = useRef(null);
|
|
|
|
|
@@ -82,7 +86,18 @@ const State = ({ show, children, setTransitioning }) => {
|
|
|
export default () => {
|
|
|
const [transitioning, setTransitioning] = useState(true);
|
|
|
const gameState = useGameState();
|
|
|
- useDirectGameLinks();
|
|
|
+ useEffect(() => {
|
|
|
+ const url = new URL(window.location.href);
|
|
|
+ for (let [param, value] of url.searchParams.entries()) {
|
|
|
+ const route = paramRouter[param];
|
|
|
+ if (route) {
|
|
|
+ url.searchParams.delete(param);
|
|
|
+ window.history.replaceState({}, document.title, url.href);
|
|
|
+ route(value);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
const needsHF = needsHeaderFooter[gameState];
|
|
|
|
|
|
return (
|