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 NotFound from './NotFound';
7 import CanonicalLinks from '../components/common/CanonicalLinks';
8 import ErrorBoundary from '../components/common/ErrorBoundary';
9 import ErrorMessage from '../components/common/ErrorMessage';
10 import Loading from '../components/common/Loading';
11 import Profile from '../components/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} />