|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
import styled from 'styled-components';
|
|
|
import GameCreationForm from '../util/GameCreationForm';
|
|
|
import { dispatch } from '../../domain/gameStore';
|
|
|
-import { getGameInfoFromLocalStorage } from '../../domain/localStorageMethods';
|
|
|
+import { useGameInfoFromLocalStorage } from '../../domain/localStorageMethods';
|
|
|
import DelayedButton from '../util/DelayedButton';
|
|
|
|
|
|
const Container = styled.div`
|
|
@@ -26,26 +26,25 @@ const RejoinContainer = styled.div`
|
|
|
align-items: center;
|
|
|
`;
|
|
|
|
|
|
+const Rejoin = ({ gameId, playerName, playerId }) => (
|
|
|
+ <RejoinContainer>
|
|
|
+ <RejoinLabel>Looks like you were in a game before that you didn't finish!</RejoinLabel>
|
|
|
+ <DelayedButton
|
|
|
+ onEnd={() => dispatch.rejoinGame(gameId, playerName, playerId)}
|
|
|
+ countDownFormatter={rem => `Rejoining in ${rem}s...`}
|
|
|
+ >
|
|
|
+ Rejoin Game?
|
|
|
+ </DelayedButton>
|
|
|
+ </RejoinContainer>
|
|
|
+);
|
|
|
+
|
|
|
export default () => {
|
|
|
- const { gameId, playerName, playerId } = getGameInfoFromLocalStorage();
|
|
|
- const rejoin = (gameId && playerName && playerId)
|
|
|
- ? (
|
|
|
- <RejoinContainer>
|
|
|
- <RejoinLabel>Looks like you were in a game before that you didn't finish!</RejoinLabel>
|
|
|
- <DelayedButton
|
|
|
- onEnd={() => dispatch.rejoinGame(gameId, playerName, playerId)}
|
|
|
- countDownFormatter={rem => `Rejoining in ${rem}s...`}
|
|
|
- >
|
|
|
- Rejoin Game?
|
|
|
- </DelayedButton>
|
|
|
- </RejoinContainer>
|
|
|
- )
|
|
|
- : null;
|
|
|
+ const { gameId, playerName, playerId } = useGameInfoFromLocalStorage();
|
|
|
|
|
|
return (
|
|
|
<Container>
|
|
|
<GameCreationForm afterCreate={gameId => dispatch.goToLobby(gameId)}/>
|
|
|
- {rejoin}
|
|
|
+ {gameId && playerName && playerId && <Rejoin {...{ gameId, playerName, playerId }} />}
|
|
|
</Container>
|
|
|
- )
|
|
|
+ );
|
|
|
};
|