Kirk Trombley 5 vuotta sitten
vanhempi
commit
fb7babc223

+ 16 - 17
client/src/components/screens/HomePage.jsx

@@ -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>
-  )
+  );
 };

+ 1 - 1
client/src/domain/localStorageMethods.js

@@ -15,7 +15,7 @@ export const clearGameInfoFromLocalStorage = () => {
   localStorage.removeItem(localStoragePlayerId);
 }
 
-export const getGameInfoFromLocalStorage = () => {
+export const useGameInfoFromLocalStorage = () => {
   const gameId = localStorage.getItem(localStorageGameId);
   const playerName = localStorage.getItem(localStoragePlayerName);
   const playerId = localStorage.getItem(localStoragePlayerId);