Skip to content

Commit 73e9464

Browse files
committed
refactor profile page
1 parent ee92e56 commit 73e9464

File tree

6 files changed

+96
-112
lines changed

6 files changed

+96
-112
lines changed

packages/app/src/app/components/ConfirmLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export const ConfirmLink: React.FC<IConfirmLinkProps> = ({
1212
...props
1313
}) => (
1414
<Link
15+
to=""
1516
onClick={(e: React.MouseEvent) => {
16-
// eslint-disable-next-line
1717
if (enabled && !confirm(message)) {
1818
e.preventDefault();
1919
e.stopPropagation();

packages/app/src/app/pages/Profile/index.js

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* @flow */
2+
import React, { useEffect } from 'react';
3+
import Helmet from 'react-helmet';
4+
import { Route, Switch, RouteComponentProps } from 'react-router-dom';
5+
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
6+
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
7+
import {
8+
profileSandboxesUrl,
9+
profileLikesUrl,
10+
} from '@codesandbox/common/lib/utils/url-generator';
11+
import { useOvermind } from 'app/overmind';
12+
import { NotFound } from 'app/pages/common/NotFound';
13+
import Header from './Header';
14+
import Navigation from './Navigation';
15+
import Showcase from './Showcase';
16+
import Sandboxes from './Sandboxes';
17+
import { Container, Content } from './elements';
18+
19+
interface IProfileProps extends RouteComponentProps<{ username: string }> {}
20+
21+
export const Profile: React.FC<IProfileProps> = ({ match }) => {
22+
const {
23+
state: {
24+
profile: { current: user, notFound },
25+
},
26+
actions: {
27+
profile: { profileMounted },
28+
},
29+
} = useOvermind();
30+
const { username } = match.params;
31+
32+
useEffect(() => {
33+
profileMounted({ username });
34+
}, [profileMounted, username]);
35+
36+
if (notFound) {
37+
return <NotFound />;
38+
}
39+
40+
if (!user) return <div />;
41+
42+
return (
43+
<Container>
44+
<Helmet>
45+
<title>{user.name || user.username} - CodeSandbox</title>
46+
</Helmet>
47+
<Header user={user} />
48+
<Content>
49+
<MaxWidth>
50+
<Navigation
51+
username={user.username}
52+
sandboxCount={user.sandboxCount}
53+
likeCount={user.givenLikeCount}
54+
/>
55+
</MaxWidth>
56+
</Content>
57+
<MaxWidth width={1024}>
58+
<Margin horizontal={2} style={{ minHeight: '60vh' }}>
59+
<Switch>
60+
<Route path={match.url} exact render={() => <Showcase />} />
61+
<Route
62+
path={`${profileSandboxesUrl(user.username)}/:page?`}
63+
// eslint-disable-next-line
64+
children={({ match: psMatch }) => (
65+
<Sandboxes
66+
source="currentSandboxes"
67+
page={psMatch.params.page && +psMatch.params.page}
68+
baseUrl={profileSandboxesUrl(user.username)}
69+
/>
70+
)}
71+
/>
72+
<Route
73+
path={`${profileLikesUrl(user.username)}/:page?`}
74+
// eslint-disable-next-line
75+
children={({ match: plMatch }) => (
76+
<Sandboxes
77+
source="currentLikedSandboxes"
78+
page={plMatch.params.page && +plMatch.params.page}
79+
baseUrl={profileLikesUrl(user.username)}
80+
/>
81+
)}
82+
/>
83+
</Switch>
84+
</Margin>
85+
</MaxWidth>
86+
</Container>
87+
);
88+
};

packages/app/src/app/pages/common/ErrorBoundary/ErrorBoundary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ErrorBoundary extends Component<
1818
props: IErrorBoundaryProps,
1919
state: IErrorBoundaryState
2020
) {
21-
if (props.location !== state.previousLocation) {
21+
if (state.previousLocation && props.location.pathname !== state.previousLocation) {
2222
return {
2323
error: null,
2424
info: null,
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { Location } from 'history';
2+
// import { Location } from 'history';
3+
import { RouteComponentProps } from 'react-router-dom';
34

45
export type ErrorInfo = {
56
componentStack: string;
@@ -10,15 +11,15 @@ export interface IFallbackComponentProps {
1011
trace?: string;
1112
}
1213

13-
export interface IErrorBoundaryProps {
14+
export interface IErrorBoundaryProps extends RouteComponentProps {
1415
children?: React.ReactNode;
15-
FallbackComponent: React.ComponentType<IFallbackComponentProps>;
16+
FallbackComponent?: React.ComponentType<IFallbackComponentProps>;
1617
onError?: (error: Error, trace: string) => void;
17-
location?: Location;
18+
// location?: Location;
1819
}
1920

2021
export interface IErrorBoundaryState {
2122
error?: Error;
2223
info?: ErrorInfo;
23-
previousLocation?: Location;
24+
previousLocation?: string;
2425
}

0 commit comments

Comments
 (0)