|
@@ -7,10 +7,8 @@ import PlayerNameInput from "../../util/PlayerNameInput";
|
|
|
import LobbyPlayerList from "./LobbyPlayerList";
|
|
|
import { joinGame } from "../../../domain/GGSHService";
|
|
|
import DelayedButton from "../../util/DelayedButton";
|
|
|
-import useObservable from "../../../hooks/useObservable";
|
|
|
-import { playerNameStore, gameIdStore, gameJoinedStore, gameStateStore } from "../../../domain/store";
|
|
|
-import { IN_ROUND } from "../../../domain/GameState";
|
|
|
import HeaderAndFooter from "../../util/HeaderAndFooter";
|
|
|
+import { dispatch, useGameId, usePlayerName, useGameJoined } from "../../../domain/gameStore";
|
|
|
|
|
|
const InfoContainer = styled.div`
|
|
|
flex: 3;
|
|
@@ -53,8 +51,8 @@ const getUrl = gameId => {
|
|
|
}
|
|
|
|
|
|
const LobbyInfo = () => {
|
|
|
- const gameId = useObservable(gameIdStore);
|
|
|
- const playerName = useObservable(playerNameStore);
|
|
|
+ const gameId = useGameId();
|
|
|
+ const playerName = usePlayerName();
|
|
|
|
|
|
return (
|
|
|
<InfoContainer>
|
|
@@ -62,7 +60,7 @@ const LobbyInfo = () => {
|
|
|
<Label>Use this link to invite other players:</Label>
|
|
|
<Label><ClickToCopy text={getUrl(gameId)} /></Label>
|
|
|
<StyledDelayButton
|
|
|
- onEnd={() => gameStateStore.set(IN_ROUND)}
|
|
|
+ onEnd={dispatch.startRound}
|
|
|
countDownFormatter={rem => `Click to cancel, ${rem}s...`}
|
|
|
>
|
|
|
Start Game
|
|
@@ -72,8 +70,8 @@ const LobbyInfo = () => {
|
|
|
};
|
|
|
|
|
|
const JoinForm = () => {
|
|
|
- const gameId = useObservable(gameIdStore);
|
|
|
- const playerName = useObservable(playerNameStore);
|
|
|
+ const gameId = useGameId();
|
|
|
+ const playerName = usePlayerName();
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [failed, setFailed] = useState(false);
|
|
|
|
|
@@ -93,8 +91,8 @@ const JoinForm = () => {
|
|
|
return;
|
|
|
}
|
|
|
setFailed(false);
|
|
|
- playerNameStore.set(playerName);
|
|
|
- gameJoinedStore.set(true);
|
|
|
+ dispatch.setPlayerName(playerName);
|
|
|
+ dispatch.joinGame();
|
|
|
};
|
|
|
const cannotJoinGame = !playerName || playerName.length === 0;
|
|
|
|
|
@@ -109,7 +107,7 @@ const JoinForm = () => {
|
|
|
}
|
|
|
|
|
|
const PreRound = ({ onStart }) => {
|
|
|
- const joined = useObservable(gameJoinedStore);
|
|
|
+ const joined = useGameJoined();
|
|
|
|
|
|
return (
|
|
|
<HeaderAndFooter>
|