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 ErrorBoundary from '../common/ErrorBoundary';
7 import ErrorMessage from '../common/ErrorMessage';
8 import Loading from '../common/Loading';
9 import NotFound from '../pages/NotFound';
10 import Profile from '../users/Profile';
13 const params = useParams();
14 const { id } = params;
16 const [error, setError] = useState(null);
17 const [loading, setLoading] = useState(true);
18 const [user, setUser] = useState(null);
22 const ctrl = new AbortController();
24 .get(`/api/users/${id}`, { signal: ctrl.signal })
28 setUser(response.data);
43 setUser(user => e.user.id === user.id ? { ...user, ...e.user } : user);
46 window.Echo.channel('App.Control')
47 .listen('UserChanged', cb);
49 window.Echo.channel('App.Control')
50 .stopListening('UserChanged', cb);
59 return <ErrorMessage error={error} />;
66 return <ErrorBoundary>
68 <title>{user.nickname || user.username}</title>
70 <Profile user={user} />