@@ -7,6 +7,10 @@ function App() {
77 const [ socket , setSocket ] = React . useState ( null ) ;
88 const [ lobby , setLobby ] = React . useState ( null ) ;
99 const [ playerId , setPlayerId ] = React . useState ( null ) ;
10+ const [
11+ gameTimeRemainingSeconds ,
12+ setGameTimeRemainingSeconds ,
13+ ] = React . useState ( null ) ;
1014
1115 React . useEffect ( ( ) => {
1216 const newSocket = io . connect ( "http://localhost:3001" ) ;
@@ -17,6 +21,12 @@ function App() {
1721 setLobby ( result ) ;
1822 } ) ;
1923
24+ newSocket . on ( "game:update_timer" , ( result ) => {
25+ console . log ( "game:update_timer" , result ) ;
26+
27+ setGameTimeRemainingSeconds ( result . timeRemainingSeconds ) ;
28+ } ) ;
29+
2030 // TODO: close socket on unmount
2131 } , [ ] ) ;
2232
@@ -25,7 +35,14 @@ function App() {
2535 }
2636
2737 if ( lobby ) {
28- return < Lobby socket = { socket } lobby = { lobby } playerId = { playerId } /> ;
38+ return (
39+ < Lobby
40+ socket = { socket }
41+ lobby = { lobby }
42+ playerId = { playerId }
43+ timeRemainingSeconds = { gameTimeRemainingSeconds }
44+ />
45+ ) ;
2946 }
3047
3148 return (
@@ -58,7 +75,7 @@ function App() {
5875 ) ;
5976}
6077
61- function Lobby ( { lobby, playerId, socket } ) {
78+ function Lobby ( { lobby, playerId, socket, timeRemainingSeconds } ) {
6279 if ( ! lobby . game ) {
6380 return (
6481 < div >
@@ -116,6 +133,9 @@ function Lobby({ lobby, playerId, socket }) {
116133 ) ;
117134 } ) }
118135 </ ul >
136+ { timeRemainingSeconds != null && (
137+ < div > Time left: { timeRemainingSeconds } </ div >
138+ ) }
119139 < div >
120140 { isActivePlayer ? (
121141 `Describe word: ${ currentRound . word } `
0 commit comments