]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/pages/User.js
fix tech basepath
[alttp.git] / resources / js / components / pages / User.js
index bb26bfae902e24fffec8501e6e6f1a34216b9546..144e4c01d86418c46bd16cc53f567556399420b8 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';
@@ -18,19 +20,22 @@ const User = () => {
 
        useEffect(() => {
                setLoading(true);
+               const ctrl = new AbortController();
                axios
-                       .get(`/api/users/${id}`)
+                       .get(`/api/users/${id}`, { signal: ctrl.signal })
                        .then(response => {
                                setError(null);
                                setLoading(false);
                                setUser(response.data);
-                               window.document.title = response.data.nickname || response.data.username;
                        })
                        .catch(error => {
                                setError(error);
                                setLoading(false);
                                setUser(null);
                        });
+               return () => {
+                       ctrl.abort();
+               };
        }, [id]);
 
        useEffect(() => {
@@ -60,6 +65,10 @@ const User = () => {
        }
 
        return <ErrorBoundary>
+               <Helmet>
+                       <title>{user.nickname || user.username}</title>
+               </Helmet>
+               <CanonicalLinks base={`/users/${user.id}`} />
                <Profile user={user} />
        </ErrorBoundary>;
 };