]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/results/List.js
improved user context
[alttp.git] / resources / js / components / results / List.js
index 14c70968cd5324823c558732df049e3a2fd715ea..911b6a53ba5526a70cb9073963190e6d0883949e 100644 (file)
@@ -5,9 +5,27 @@ import Item from './Item';
 import { sortByFinished, sortByResult } from '../../helpers/Participant';
 import { maySeeResults } from '../../helpers/permissions';
 import { getRunners } from '../../helpers/Tournament';
-import { withUser } from '../../helpers/UserContext';
+import { compareResult } from '../../helpers/Result';
+import { useUser } from '../../hooks/user';
 
-const List = ({ round, tournament, user }) => {
+const List = ({ round, tournament }) => {
+       const { user } = useUser();
+
+       if (tournament.type === 'open-async') {
+               const results = maySeeResults(user, tournament, round)
+                       ? (round.results || []).sort(compareResult)
+                       : round.results || [];
+               return <div className="results d-flex flex-wrap">
+                       {results.map(result =>
+                               <Item
+                                       key={result.id}
+                                       round={round}
+                                       tournament={tournament}
+                                       user={result.user}
+                               />
+                       )}
+               </div>;
+       }
        const runners = maySeeResults(user, tournament, round)
                ? sortByResult(getRunners(tournament), round)
                : sortByFinished(getRunners(tournament), round);
@@ -15,9 +33,9 @@ const List = ({ round, tournament, user }) => {
                {runners.map(participant =>
                        <Item
                                key={participant.id}
-                               participant={participant}
                                round={round}
                                tournament={tournament}
+                               user={participant.user}
                        />
                )}
        </div>;
@@ -25,13 +43,16 @@ const List = ({ round, tournament, user }) => {
 
 List.propTypes = {
        round: PropTypes.shape({
+               results: PropTypes.arrayOf(PropTypes.shape({
+               })),
        }),
        tournament: PropTypes.shape({
                participants: PropTypes.arrayOf(PropTypes.shape({
                })),
-       }),
-       user: PropTypes.shape({
+               type: PropTypes.string,
+               users: PropTypes.arrayOf(PropTypes.shape({
+               })),
        }),
 };
 
-export default withUser(List);
+export default List;