]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/results/List.js
compact keysanity tracker
[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 { compareResult } from '../../helpers/Result';
9 import { useUser } from '../../hooks/user';
10
11 const List = ({ round, tournament }) => {
12         const { user } = useUser();
13
14         if (tournament.type === 'open-async') {
15                 const results = maySeeResults(user, tournament, round)
16                         ? (round.results || []).sort(compareResult)
17                         : round.results || [];
18                 return <div className="results d-flex flex-wrap">
19                         {results.map(result =>
20                                 <Item
21                                         key={result.id}
22                                         round={round}
23                                         tournament={tournament}
24                                         user={result.user}
25                                 />
26                         )}
27                 </div>;
28         }
29         const runners = maySeeResults(user, tournament, round)
30                 ? sortByResult(getRunners(tournament), round)
31                 : sortByFinished(getRunners(tournament), round);
32         return <div className="results d-flex flex-wrap">
33                 {runners.map(participant =>
34                         <Item
35                                 key={participant.id}
36                                 round={round}
37                                 tournament={tournament}
38                                 user={participant.user}
39                         />
40                 )}
41         </div>;
42 };
43
44 List.propTypes = {
45         round: PropTypes.shape({
46                 results: PropTypes.arrayOf(PropTypes.shape({
47                 })),
48         }),
49         tournament: PropTypes.shape({
50                 participants: PropTypes.arrayOf(PropTypes.shape({
51                 })),
52                 type: PropTypes.string,
53                 users: PropTypes.arrayOf(PropTypes.shape({
54                 })),
55         }),
56 };
57
58 export default List;