]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/pages/Tournament.js
basic auto tracking
[alttp.git] / resources / js / pages / Tournament.js
index 20f34ceda7afd84ad8a35275d85f7948cb462c40..ecaab6c97807bf1968b7e1732cf8c7d624a0a85b 100644 (file)
@@ -10,6 +10,8 @@ import Loading from '../components/common/Loading';
 import NotFound from '../pages/NotFound';
 import Detail from '../components/tournament/Detail';
 import {
+       canLoadMoreRounds,
+       getLastRound,
        patchApplication,
        patchParticipant,
        patchResult,
@@ -19,7 +21,7 @@ import {
        sortParticipants,
 } from '../helpers/Tournament';
 
-const Tournament = () => {
+export const Component = () => {
        const params = useParams();
        const { id } = params;
 
@@ -65,7 +67,6 @@ const Tournament = () => {
                                }
                        })
                        .listen('ParticipantChanged', e => {
-                               console.log(e);
                                if (e.participant) {
                                        setTournament(tournament => patchParticipant(tournament, e.participant));
                                }
@@ -98,6 +99,21 @@ const Tournament = () => {
                };
        }, [id]);
 
+       const moreRounds = React.useCallback(async () => {
+               const last_round = getLastRound(tournament);
+               if (!last_round) return;
+               console.log(last_round);
+               const last_known = last_round.number;
+               const rsp = await axios.get(
+                       `/api/tournaments/${id}/more-rounds`,
+                       { params: { last_known } },
+               );
+               setTournament(tournament => ({
+                       ...tournament,
+                       rounds: [...tournament.rounds, ...rsp.data],
+               }));
+       }, [id, tournament]);
+
        useEffect(() => {
                const cb = (e) => {
                        if (e.user) {
@@ -133,8 +149,10 @@ const Tournament = () => {
                        <title>{tournament.title}</title>
                </Helmet>
                <CanonicalLinks base={`/tournaments/${tournament.id}`} />
-               <Detail addRound={addRound} tournament={tournament} />
+               <Detail
+                       addRound={addRound}
+                       moreRounds={canLoadMoreRounds(tournament) ? moreRounds : null}
+                       tournament={tournament}
+               />
        </ErrorBoundary>;
 };
-
-export default Tournament;