1
1
import React , { Component } from 'react' ;
2
- import { GamesController } from '../api/controllers/gamesController.js ' ;
2
+ import GameHeader from './GameHeader.jsx ' ;
3
3
import { Game , GameStatuses } from '../api/models/game.js' ;
4
4
import { newGame , userJoinGame , userLeaveGame } from '../api/methods/games.js' ;
5
5
@@ -12,71 +12,100 @@ export default class GameList extends Component {
12
12
userLeaveGame . call ( { gameId : gameId } ) ;
13
13
}
14
14
15
- handleJoinGame ( gameId ) {
15
+ handleJoinGame ( gameId ) {
16
16
userJoinGame . call ( { gameId : gameId } ) ;
17
17
}
18
18
19
- handleEnterGame ( gameId ) {
19
+ handleEnterGame ( gameId ) {
20
20
this . props . enterGameHandler ( gameId ) ;
21
21
}
22
22
23
- activeGames ( ) {
23
+ activeGames ( ) {
24
24
return _ . filter ( this . props . games , ( game ) => {
25
25
return game . status === GameStatuses . WAITING || game . status === GameStatuses . STARTED ;
26
26
} ) ;
27
27
}
28
28
29
- myCurrentGameId ( ) {
29
+ myCurrentGameId ( ) {
30
30
let game = _ . find ( this . activeGames ( ) , ( game ) => {
31
31
return game . userIndex ( this . props . user ) !== null ;
32
32
} ) ;
33
33
return game === undefined ? null : game . _id ;
34
34
}
35
35
36
- renderPlayers ( game ) {
37
- let player1 = game . players . length > 0 ? game . players [ 0 ] . username : '' ;
38
- let player2 = game . players . length > 1 ? game . players [ 1 ] . username : '' ;
36
+ renderPlayers ( game ) {
37
+ let player1 = game . players . length > 0 ? game . players [ 0 ] . username : '(waiting) ' ;
38
+ let player2 = game . players . length > 1 ? game . players [ 1 ] . username : '(waiting) ' ;
39
39
return (
40
- < span > [{ player1 } ] vs [{ player2 } ]</ span >
40
+ < div >
41
+ < div >
42
+ < i className = "user icon" > </ i > { player1 }
43
+ </ div >
44
+ < div >
45
+ < i className = "user icon" > </ i > { player2 }
46
+ </ div >
47
+ </ div >
41
48
)
42
49
}
43
50
44
- render ( ) {
51
+ render ( ) {
45
52
return (
46
- < div >
47
- < div >
48
- < h1 > List of games</ h1 >
49
- { this . activeGames ( ) . map ( ( game , index ) => {
50
- return (
51
- < div key = { game . _id } >
52
- < span > Game { index + 1 } </ span >
53
- { this . renderPlayers ( game ) }
53
+ < div className = "ui container" >
54
+ < GameHeader user = { this . props . user } />
54
55
55
- { /* can leave only if user is in the game, and the game is not started */ }
56
- { this . myCurrentGameId ( ) === game . _id && game . status === GameStatuses . WAITING ? (
57
- < button onClick = { this . handleLeaveGame . bind ( this , game . _id ) } > Leave</ button >
58
- ) : null }
56
+ < h1 className = "ui top attached header" > List of games</ h1 >
57
+ < div className = "ui attached segment" >
58
+ < div className = "ui three cards" >
59
+ { this . activeGames ( ) . map ( ( game , index ) => {
60
+ return (
61
+ < div key = { game . _id } className = "ui card" >
62
+ < div className = "content" >
63
+ < div className = "header" >
64
+ { game . status === GameStatuses . WAITING ? (
65
+ < span className = "ui right yellow corner label" >
66
+ < i className = "idea icon" />
67
+ </ span >
68
+ ) : null }
69
+ Game { index + 1 }
70
+ </ div >
71
+ </ div >
72
+ < div className = "content" >
73
+ { this . renderPlayers ( game ) }
74
+ </ div >
59
75
60
- { /* can join only if user is not in any game, and the game is not started */ }
61
- { this . myCurrentGameId ( ) === null && game . status === GameStatuses . WAITING ? (
62
- < button onClick = { this . handleJoinGame . bind ( this , game . _id ) } > Join</ button >
63
- ) : null }
76
+ < div className = "extra content" >
77
+ { /* can leave only if user is in the game, and the game is not started */ }
78
+ { this . myCurrentGameId ( ) === game . _id && game . status === GameStatuses . WAITING ? (
79
+ < button className = "ui red button" onClick = { this . handleLeaveGame . bind ( this , game . _id ) } > Leave</ button >
80
+ ) : null }
64
81
65
- { /* can enter only if the game is started */ }
66
- { game . status === GameStatuses . STARTED ? (
67
- < button onClick = { this . handleEnterGame . bind ( this , game . _id ) } > Enter</ button >
68
- ) : null }
69
- </ div >
70
- )
71
- } ) }
72
- </ div >
82
+ { /* can join only if user is not in any game, and the game is not started */ }
83
+ { this . myCurrentGameId ( ) === null && game . status === GameStatuses . WAITING ? (
84
+ < button className = "ui green button" onClick = { this . handleJoinGame . bind ( this , game . _id ) } > Join</ button >
85
+ ) : null }
73
86
74
- { /* Only show new game button if player is not in any room */ }
75
- { this . myCurrentGameId ( ) === null ? (
76
- < div >
77
- < button onClick = { this . handleNewGame . bind ( this ) } > New Game</ button >
87
+ { /* can enter only if the game is started */ }
88
+ { game . status === GameStatuses . STARTED ? (
89
+ < button className = "ui blue button" onClick = { this . handleEnterGame . bind ( this , game . _id ) } > Enter</ button >
90
+ ) : null }
91
+
92
+ { /* just a invisible dummy button to make up the space */ }
93
+ < button className = "ui button" style = { { visibility : "hidden" } } > Dummy</ button >
94
+ </ div >
95
+ </ div >
96
+ )
97
+ } ) }
78
98
</ div >
79
- ) : null }
99
+
100
+ { /* Only show new game button if player is not in any room */ }
101
+ </ div >
102
+ < div className = "ui attached segment" >
103
+ { this . myCurrentGameId ( ) === null ? (
104
+ < div >
105
+ < button className = "ui green button" onClick = { this . handleNewGame . bind ( this ) } > New Game</ button >
106
+ </ div >
107
+ ) : null }
108
+ </ div >
80
109
</ div >
81
110
)
82
111
}
0 commit comments