]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/pages/Tournament.js
more alternate/canonical links
[alttp.git] / resources / js / components / pages / Tournament.js
index 00a19343c11b1c99c59d59937946f6ce85f89b17..d148059fef2cda83250afa2a5e290dbdaaa0e07a 100644 (file)
@@ -1,7 +1,9 @@
 import axios from 'axios';
 import React, { useEffect, useState } from 'react';
+import { Helmet } from 'react-helmet';
 import { useParams } from 'react-router-dom';
 
+import CanonicalLinks from '../common/CanonicalLinks';
 import ErrorBoundary from '../common/ErrorBoundary';
 import ErrorMessage from '../common/ErrorMessage';
 import Loading from '../common/Loading';
@@ -26,20 +28,23 @@ const Tournament = () => {
        const [tournament, setTournament] = useState(null);
 
        useEffect(() => {
+               const ctrl = new AbortController();
                setLoading(true);
                axios
-                       .get(`/api/tournaments/${id}`)
+                       .get(`/api/tournaments/${id}`, { signal: ctrl.signal })
                        .then(response => {
                                setError(null);
                                setLoading(false);
                                setTournament(sortParticipants(response.data));
-                               window.document.title = response.data.title;
                        })
                        .catch(error => {
                                setError(error);
                                setLoading(false);
                                setTournament(null);
                        });
+               return () => {
+                       ctrl.abort();
+               };
        }, [id]);
 
        useEffect(() => {
@@ -124,6 +129,10 @@ const Tournament = () => {
        };
 
        return <ErrorBoundary>
+               <Helmet>
+                       <title>{tournament.title}</title>
+               </Helmet>
+               <CanonicalLinks base={`/tournaments/${tournament.id}`} />
                <Detail addRound={addRound} tournament={tournament} />
        </ErrorBoundary>;
 };