|
1 | 1 | import React from 'react'; |
| 2 | +import { useSelector, useDispatch } from 'react-redux'; |
2 | 3 | import moment from 'moment'; |
3 | 4 | import ResultIcon from './ResultIcon'; |
4 | 5 | import UserInfo from '../../containers/UserInfo'; |
5 | 6 | import GameLevelBadge from '../GameLevelBadge'; |
6 | 7 |
|
7 | | -const CompletedGames = ({ games, onShowMoreButtonClick = null }) => ( |
8 | | - <div className="table-responsive"> |
9 | | - <table className="table table-sm table-striped border-gray border mb-0"> |
10 | | - <thead> |
11 | | - <tr> |
12 | | - <th className="p-3 border-0">Level</th> |
13 | | - <th className="p-3 border-0 text-center" colSpan={2}> |
14 | | - Players |
15 | | - </th> |
16 | | - <th className="p-3 border-0">Date</th> |
17 | | - <th className="p-3 border-0">Actions</th> |
18 | | - </tr> |
19 | | - </thead> |
20 | | - <tbody> |
21 | | - {games.map(game => ( |
22 | | - <tr key={game.id}> |
23 | | - <td className="p-3 align-middle text-nowrap"> |
24 | | - <GameLevelBadge level={game.level} /> |
25 | | - </td> |
26 | | - <td className="p-3 align-middle text-nowrap cb-username-td text-truncate"> |
27 | | - <div className="d-flex align-items-center"> |
28 | | - <ResultIcon gameId={game.id} player1={game.players[0]} player2={game.players[1]} /> |
29 | | - <UserInfo user={game.players[0]} /> |
30 | | - </div> |
31 | | - </td> |
32 | | - <td className="p-3 align-middle text-nowrap cb-username-td text-truncate"> |
33 | | - <div className="d-flex align-items-center"> |
34 | | - <ResultIcon gameId={game.id} player1={game.players[1]} player2={game.players[0]} /> |
35 | | - <UserInfo user={game.players[1]} /> |
36 | | - </div> |
37 | | - </td> |
38 | | - <td className="p-3 align-middle text-nowrap">{moment.utc(game.finishsAt).local().format('MM.DD HH:mm')}</td> |
39 | | - <td className="p-3 align-middle"> |
40 | | - <a type="button" className="btn btn-outline-orange btn-sm" href={`/games/${game.id}`}> |
41 | | - Show |
42 | | - </a> |
43 | | - </td> |
| 8 | +const CompletedGames = ({ games, loadNextPage = null }) => { |
| 9 | + const { nextPage, totalPages } = useSelector(state => state.completedGames); |
| 10 | + const dispatch = useDispatch(); |
| 11 | + |
| 12 | + return ( |
| 13 | + <div className="table-responsive"> |
| 14 | + <table className="table table-sm table-striped border-gray border mb-0"> |
| 15 | + <thead> |
| 16 | + <tr> |
| 17 | + <th className="p-3 border-0">Level</th> |
| 18 | + <th className="p-3 border-0 text-center" colSpan={2}> |
| 19 | + Players |
| 20 | + </th> |
| 21 | + <th className="p-3 border-0">Date</th> |
| 22 | + <th className="p-3 border-0">Actions</th> |
44 | 23 | </tr> |
| 24 | + </thead> |
| 25 | + <tbody> |
| 26 | + {games.map(game => ( |
| 27 | + <tr key={game.id}> |
| 28 | + <td className="p-3 align-middle text-nowrap"> |
| 29 | + <GameLevelBadge level={game.level} /> |
| 30 | + </td> |
| 31 | + <td className="p-3 align-middle text-nowrap cb-username-td text-truncate"> |
| 32 | + <div className="d-flex align-items-center"> |
| 33 | + <ResultIcon gameId={game.id} player1={game.players[0]} player2={game.players[1]} /> |
| 34 | + <UserInfo user={game.players[0]} /> |
| 35 | + </div> |
| 36 | + </td> |
| 37 | + <td className="p-3 align-middle text-nowrap cb-username-td text-truncate"> |
| 38 | + <div className="d-flex align-items-center"> |
| 39 | + <ResultIcon gameId={game.id} player1={game.players[1]} player2={game.players[0]} /> |
| 40 | + <UserInfo user={game.players[1]} /> |
| 41 | + </div> |
| 42 | + </td> |
| 43 | + <td className="p-3 align-middle text-nowrap">{moment.utc(game.finishsAt).local().format('MM.DD HH:mm')}</td> |
| 44 | + <td className="p-3 align-middle"> |
| 45 | + <a type="button" className="btn btn-outline-orange btn-sm" href={`/games/${game.id}`}> |
| 46 | + Show |
| 47 | + </a> |
| 48 | + </td> |
| 49 | + </tr> |
45 | 50 | ))} |
46 | | - </tbody> |
47 | | - </table> |
48 | | - { onShowMoreButtonClick |
| 51 | + </tbody> |
| 52 | + </table> |
| 53 | + { loadNextPage !== null && nextPage < totalPages |
49 | 54 | ? ( |
50 | | - <button type="button" className="mt-2 btn btn-light" onClick={() => onShowMoreButtonClick()}> |
| 55 | + <button type="button" className="mt-2 btn btn-light" onClick={() => dispatch(loadNextPage(nextPage))}> |
51 | 56 | Show More |
52 | 57 | </button> |
53 | 58 | ) : null} |
54 | | - </div> |
55 | | -); |
| 59 | + </div> |
| 60 | + ); |
| 61 | +}; |
56 | 62 |
|
57 | 63 | export default CompletedGames; |
0 commit comments