]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/results/List.js
3d1bdfa8f27c9ff0147832934ce81975a8bee2c0
[alttp.git] / resources / js / components / results / List.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3
4 import Item from './Item';
5 import { sortByFinished, sortByResult } from '../../helpers/Participant';
6 import { maySeeResults } from '../../helpers/permissions';
7 import { getRunners } from '../../helpers/Tournament';
8 import { withUser } from '../../helpers/UserContext';
9
10 const List = ({ round, tournament, user }) => {
11         if (tournament.type === 'open-async') {
12                 const results = round.results || [];
13                 return <div className="results d-flex flex-wrap">
14                         {results.map(result =>
15                                 <Item
16                                         key={result.id}
17                                         round={round}
18                                         tournament={tournament}
19                                         user={result.user}
20                                 />
21                         )}
22                 </div>;
23         }
24         const runners = maySeeResults(user, tournament, round)
25                 ? sortByResult(getRunners(tournament), round)
26                 : sortByFinished(getRunners(tournament), round);
27         return <div className="results d-flex flex-wrap">
28                 {runners.map(participant =>
29                         <Item
30                                 key={participant.id}
31                                 round={round}
32                                 tournament={tournament}
33                                 user={participant.user}
34                         />
35                 )}
36         </div>;
37 };
38
39 List.propTypes = {
40         round: PropTypes.shape({
41                 results: PropTypes.arrayOf(PropTypes.shape({
42                 })),
43         }),
44         tournament: PropTypes.shape({
45                 participants: PropTypes.arrayOf(PropTypes.shape({
46                 })),
47                 type: PropTypes.string,
48                 users: PropTypes.arrayOf(PropTypes.shape({
49                 })),
50         }),
51         user: PropTypes.shape({
52         }),
53 };
54
55 export default withUser(List);