11import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth' ;
2- import Margin from '@codesandbox/common/lib/components/spacing/Margin' ;
32import {
43 profileLikesUrl ,
54 profileSandboxesUrl ,
65} from '@codesandbox/common/lib/utils/url-generator' ;
6+ import React , { FunctionComponent , useEffect } from 'react' ;
7+ import { Helmet } from 'react-helmet' ;
8+ import { Route , RouteComponentProps , Switch } from 'react-router-dom' ;
9+
710import { useOvermind } from 'app/overmind' ;
811import { NotFound } from 'app/pages/common/NotFound' ;
9- import React , { useEffect } from 'react' ;
10- import { Helmet } from 'react-helmet' ;
11- import { Route , Switch } from 'react-router-dom' ;
1212
13- import { Container , Content } from './elements' ;
13+ import { Container , Content , Margin } from './elements' ;
1414import Header from './Header' ;
1515import Navigation from './Navigation' ;
1616import { Sandboxes } from './Sandboxes' ;
1717import { Showcase } from './Showcase' ;
1818
19- interface IProfileProps {
20- match : {
21- params : { username : string } ;
22- url : string ;
23- } ;
24- }
25-
26- const Profile : React . FC < IProfileProps > = ( {
19+ type Props = RouteComponentProps < { username : string } > ;
20+ export const Profile : FunctionComponent < Props > = ( {
2721 match : {
2822 params : { username } ,
2923 url,
3024 } ,
3125} ) => {
3226 const {
33- state : {
34- profile : { current : user , notFound } ,
35- } ,
3627 actions : {
3728 profile : { profileMounted } ,
3829 } ,
30+ state : {
31+ profile : { current : user , notFound } ,
32+ } ,
3933 } = useOvermind ( ) ;
4034
4135 useEffect ( ( ) => {
42- profileMounted ( { username } ) ;
36+ profileMounted ( username ) ;
4337 } , [ profileMounted , username ] ) ;
4438
4539 if ( notFound ) {
4640 return < NotFound /> ;
4741 }
4842
4943 if ( ! user ) {
50- return < div /> ;
44+ return null ;
5145 }
5246
5347 return (
5448 < Container >
5549 < Helmet >
5650 < title > { user . name || user . username } - CodeSandbox</ title >
5751 </ Helmet >
52+
5853 < Header user = { user } />
54+
5955 < Content >
6056 < MaxWidth >
6157 < Navigation
62- username = { user . username }
63- sandboxCount = { user . sandboxCount }
6458 likeCount = { user . givenLikeCount }
59+ sandboxCount = { user . sandboxCount }
60+ username = { user . username }
6561 />
6662 </ MaxWidth >
6763 </ Content >
64+
6865 < MaxWidth width = { 1024 } >
69- < Margin horizontal = { 2 } style = { { minHeight : '60vh' } } >
66+ < Margin horizontal = { 2 } >
7067 < Switch >
71- < Route path = { url } exact render = { ( ) => < Showcase /> } />
68+ < Route component = { Showcase } exact path = { url } />
69+
7270 < Route
7371 path = { `${ profileSandboxesUrl ( user . username ) } /:page?` }
74- render = { ( { match } ) => (
72+ render = { ( { match } : RouteComponentProps < { page ?: string } > ) => (
7573 < Sandboxes
76- source = "currentSandboxes"
77- page = { match . params . page && + match . params . page }
7874 baseUrl = { profileSandboxesUrl ( user . username ) }
75+ page = { Number ( match . params . page ) || 1 }
76+ source = "currentSandboxes"
7977 />
8078 ) }
8179 />
80+
8281 < Route
8382 path = { `${ profileLikesUrl ( user . username ) } /:page?` }
84- render = { ( { match } ) => (
83+ render = { ( { match } : RouteComponentProps < { page ?: string } > ) => (
8584 < Sandboxes
86- source = "currentLikedSandboxes"
87- page = { match . params . page && + match . params . page }
8885 baseUrl = { profileLikesUrl ( user . username ) }
86+ page = { Number ( match . params . page ) || 1 }
87+ source = "currentLikedSandboxes"
8988 />
9089 ) }
9190 />
@@ -95,5 +94,3 @@ const Profile: React.FC<IProfileProps> = ({
9594 </ Container >
9695 ) ;
9796} ;
98-
99- export default Profile ;
0 commit comments