Skip to content

Commit c160a7e

Browse files
committed
refactor profile page
1 parent b3bb9e2 commit c160a7e

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export const ConfirmLink: React.FC<IConfirmLinkProps> = ({
1313
...props
1414
}) => (
1515
<Link
16+
to=""
1617
onClick={(e: React.MouseEvent) => {
17-
// eslint-disable-next-line
1818
if (enabled && !confirm(message)) {
1919
e.preventDefault();
2020
e.stopPropagation();
Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect } from 'react';
2-
import { Helmet } from 'react-helmet';
3-
import { Route, Switch } from 'react-router-dom';
2+
import Helmet from 'react-helmet';
3+
import { Route, Switch, RouteComponentProps } from 'react-router-dom';
44
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
55
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
66
import {
@@ -15,19 +15,9 @@ import Showcase from './Showcase';
1515
import Sandboxes from './Sandboxes';
1616
import { Container, Content } from './elements';
1717

18-
interface IProfileProps {
19-
match: {
20-
params: { username: string };
21-
url: string;
22-
};
23-
}
18+
interface IProfileProps extends RouteComponentProps<{ username: string }> {}
2419

25-
const Profile: React.FC<IProfileProps> = ({
26-
match: {
27-
params: { username },
28-
url,
29-
},
30-
}) => {
20+
export const Profile: React.FC<IProfileProps> = ({ match }) => {
3121
const {
3222
state: {
3323
profile: { current: user, notFound },
@@ -36,6 +26,7 @@ const Profile: React.FC<IProfileProps> = ({
3626
profile: { profileMounted },
3727
},
3828
} = useOvermind();
29+
const { username } = match.params;
3930

4031
useEffect(() => {
4132
profileMounted({ username });
@@ -45,9 +36,7 @@ const Profile: React.FC<IProfileProps> = ({
4536
return <NotFound />;
4637
}
4738

48-
if (!user) {
49-
return <div />;
50-
}
39+
if (!user) return <div />;
5140

5241
return (
5342
<Container>
@@ -67,23 +56,25 @@ const Profile: React.FC<IProfileProps> = ({
6756
<MaxWidth width={1024}>
6857
<Margin horizontal={2} style={{ minHeight: '60vh' }}>
6958
<Switch>
70-
<Route path={url} exact render={() => <Showcase />} />
59+
<Route path={match.url} exact render={() => <Showcase />} />
7160
<Route
7261
path={`${profileSandboxesUrl(user.username)}/:page?`}
73-
render={({ match }) => (
62+
// eslint-disable-next-line
63+
children={({ match: psMatch }) => (
7464
<Sandboxes
7565
source="currentSandboxes"
76-
page={match.params.page && +match.params.page}
66+
page={psMatch.params.page && +psMatch.params.page}
7767
baseUrl={profileSandboxesUrl(user.username)}
7868
/>
7969
)}
8070
/>
8171
<Route
8272
path={`${profileLikesUrl(user.username)}/:page?`}
83-
render={({ match }) => (
73+
// eslint-disable-next-line
74+
children={({ match: plMatch }) => (
8475
<Sandboxes
8576
source="currentLikedSandboxes"
86-
page={match.params.page && +match.params.page}
77+
page={plMatch.params.page && +plMatch.params.page}
8778
baseUrl={profileLikesUrl(user.username)}
8879
/>
8980
)}
@@ -93,6 +84,4 @@ const Profile: React.FC<IProfileProps> = ({
9384
</MaxWidth>
9485
</Container>
9586
);
96-
};
97-
98-
export default Profile;
87+
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ErrorBoundary extends Component<
1414
props: IErrorBoundaryProps,
1515
state: IErrorBoundaryState
1616
) {
17-
if (props.location !== state.previousLocation) {
17+
if (state.previousLocation && props.location.pathname !== state.previousLocation) {
1818
return {
1919
error: null,
2020
info: null,
Lines changed: 5 additions & 4 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;
1516
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)