1 import axios from 'axios';
2 import React, { useEffect, useState } from 'react';
3 import { Helmet } from 'react-helmet';
4 import { useParams } from 'react-router-dom';
6 import CanonicalLinks from '../common/CanonicalLinks';
7 import ErrorBoundary from '../common/ErrorBoundary';
8 import ErrorMessage from '../common/ErrorMessage';
9 import Loading from '../common/Loading';
10 import NotFound from '../pages/NotFound';
11 import Profile from '../users/Profile';
14 const params = useParams();
15 const { id } = params;
17 const [error, setError] = useState(null);
18 const [loading, setLoading] = useState(true);
19 const [user, setUser] = useState(null);
23 const ctrl = new AbortController();
25 .get(`/api/users/${id}`, { signal: ctrl.signal })
29 setUser(response.data);
44 setUser(user => e.user.id === user.id ? { ...user, ...e.user } : user);
47 window.Echo.channel('App.Control')
48 .listen('UserChanged', cb);
50 window.Echo.channel('App.Control')
51 .stopListening('UserChanged', cb);
60 return <ErrorMessage error={error} />;
67 return <ErrorBoundary>
69 <title>{user.nickname || user.username}</title>
71 <CanonicalLinks base={`/users/${user.id}`} />
72 <Profile user={user} />