Skip to content

Commit c96b102

Browse files
malwilleyCompuIves
authored andcommitted
Refactor profile page component to use TS/hooks/Overmind. (#2729)
1 parent 2c62b64 commit c96b102

File tree

9 files changed

+132
-137
lines changed

9 files changed

+132
-137
lines changed

packages/app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@
237237
"@types/prop-types": "^15.7.0",
238238
"@types/react": "^16.8.12",
239239
"@types/react-dom": "^16.8.3",
240+
"@types/react-helmet": "^5.0.11",
240241
"@types/react-icons": "2.2.7",
242+
"@types/react-router-dom": "^5.1.0",
241243
"@types/react-stripe-elements": "^1.3.2",
242244
"@types/resolve": "^0.0.8",
243245
"@types/socket.io-client": "^1.4.32",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
44
interface IConfirmLinkProps {
55
enabled: boolean;
66
message: string;
7+
to: string;
78
}
89

910
export const ConfirmLink: React.FC<IConfirmLinkProps> = ({

packages/app/src/app/pages/Dashboard/Content/routes/Templates/Templates.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import Helmet from 'react-helmet';
2+
import { Helmet } from 'react-helmet';
33
import { sortBy } from 'lodash-es';
44
import { useQuery } from '@apollo/react-hooks';
55
import track from '@codesandbox/common/lib/utils/analytics';

packages/app/src/app/pages/Patron/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect } from 'react';
2-
import Helmet from 'react-helmet';
2+
import { Helmet } from 'react-helmet';
33
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
44
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
55
import Centered from '@codesandbox/common/lib/components/flex/Centered';

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

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ export class ErrorBoundary extends Component<
66
IErrorBoundaryProps,
77
IErrorBoundaryState
88
> {
9-
static defaultProps = {
10-
FallbackComponent: CodeSadbox,
11-
};
12-
139
static getDerivedStateFromError(error: Error) {
1410
return { error };
1511
}
@@ -48,7 +44,7 @@ export class ErrorBoundary extends Component<
4844
}
4945

5046
render() {
51-
const { children, FallbackComponent } = this.props;
47+
const { children, FallbackComponent = CodeSadbox } = this.props;
5248
const { error, info } = this.state;
5349

5450
return error !== null ? (

packages/app/src/app/pages/common/ErrorBoundary/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { Location } from 'history';
3+
import { RouteComponentProps } from 'react-router';
34

45
export type ErrorInfo = {
56
componentStack: string;
@@ -10,11 +11,10 @@ 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;
1818
}
1919

2020
export interface IErrorBoundaryState {

yarn.lock

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,6 +4097,13 @@
40974097
dependencies:
40984098
"@types/react" "*"
40994099

4100+
"@types/react-helmet@^5.0.11":
4101+
version "5.0.11"
4102+
resolved "https://registry.yarnpkg.com/@types/react-helmet/-/react-helmet-5.0.11.tgz#d2642af4658e7b97accb46ea8b00d6dc614c99fa"
4103+
integrity sha512-id9DjHp/+Cm+x3etN+EWs5OP76PPpz8jXw+iN9xcXltssF0KHNjAzlan///ASXegEewaItlw5FhFnoLxRUJQ9g==
4104+
dependencies:
4105+
"@types/react" "*"
4106+
41004107
"@types/react-icon-base@*":
41014108
version "2.1.3"
41024109
resolved "https://registry.yarnpkg.com/@types/react-icon-base/-/react-icon-base-2.1.3.tgz#0faf840b854a9dbc3fa6fe1935c7c40eb4153114"
@@ -4120,6 +4127,23 @@
41204127
"@types/prop-types" "*"
41214128
"@types/react" "*"
41224129

4130+
"@types/react-router-dom@^5.1.0":
4131+
version "5.1.0"
4132+
resolved "https://registry.yarnpkg.com/@types/react-router-dom/-/react-router-dom-5.1.0.tgz#8baa84a7fa8c8e7797fb3650ca51f93038cb4caf"
4133+
integrity sha512-YCh8r71pL5p8qDwQf59IU13hFy/41fDQG/GeOI3y+xmD4o0w3vEPxE8uBe+dvOgMoDl0W1WUZsWH0pxc1mcZyQ==
4134+
dependencies:
4135+
"@types/history" "*"
4136+
"@types/react" "*"
4137+
"@types/react-router" "*"
4138+
4139+
"@types/react-router@*":
4140+
version "5.1.1"
4141+
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.1.tgz#e0b827556abc70da3473d05daf074c839d6852aa"
4142+
integrity sha512-S7SlFAPb7ZKr6HHMW0kLHGcz8pyJSL0UdM+JtlWthDqKUWwr7E6oPXuHgkofDI8dKCm16slg8K8VCf5pZJquaA==
4143+
dependencies:
4144+
"@types/history" "*"
4145+
"@types/react" "*"
4146+
41234147
"@types/react-stripe-elements@^1.3.2":
41244148
version "1.3.2"
41254149
resolved "https://registry.yarnpkg.com/@types/react-stripe-elements/-/react-stripe-elements-1.3.2.tgz#02ed6802b16366b4ebc6b85b8bd3e8befa553b79"
@@ -14004,9 +14028,6 @@ inflight@^1.0.4:
1400414028
version "1.0.6"
1400514029
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
1400614030
integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
14007-
dependencies:
14008-
once "^1.3.0"
14009-
wrappy "1"
1401014031

1401114032
inherits@1:
1401214033
version "1.0.2"
@@ -14298,8 +14319,6 @@ is-accessor-descriptor@^0.1.6:
1429814319
version "0.1.6"
1429914320
resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz#a9e12cb3ae8d876727eeef3843f8a0897b5c98d6"
1430014321
integrity sha1-qeEss66Nh2cn7u84Q/igiXtcmNY=
14301-
dependencies:
14302-
kind-of "^3.0.2"
1430314322

1430414323
is-accessor-descriptor@^1.0.0:
1430514324
version "1.0.0"
@@ -15788,8 +15807,6 @@ json-stable-stringify-without-jsonify@^1.0.1:
1578815807
json-stable-stringify@^1.0.1:
1578915808
version "1.0.1"
1579015809
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af"
15791-
dependencies:
15792-
jsonify "~0.0.0"
1579315810

1579415811
json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
1579515812
version "5.0.1"
@@ -16046,9 +16063,6 @@ levn@^0.3.0, levn@~0.3.0:
1604616063
version "0.3.0"
1604716064
resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee"
1604816065
integrity sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=
16049-
dependencies:
16050-
prelude-ls "~1.1.2"
16051-
type-check "~0.3.2"
1605216066

1605316067
[email protected], lie@~3.1.0:
1605416068
version "3.1.1"
@@ -19212,10 +19226,6 @@ path-type@^1.0.0:
1921219226
version "1.1.0"
1921319227
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
1921419228
integrity sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=
19215-
dependencies:
19216-
graceful-fs "^4.1.2"
19217-
pify "^2.0.0"
19218-
pinkie-promise "^2.0.0"
1921919229

1922019230
path-type@^2.0.0:
1922119231
version "2.0.0"
@@ -19228,8 +19238,6 @@ path-type@^3.0.0:
1922819238
version "3.0.0"
1922919239
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
1923019240
integrity sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==
19231-
dependencies:
19232-
pify "^3.0.0"
1923319241

1923419242
path-type@^4.0.0:
1923519243
version "4.0.0"
@@ -22084,7 +22092,7 @@ regex-cache@^0.4.2:
2208422092
dependencies:
2208522093
is-equal-shallow "^0.1.3"
2208622094

22087-
regex-not@^1.0.0, regex-not@^1.0.2:
22095+
regex-not@^1.0.0:
2208822096
version "1.0.2"
2208922097
resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
2209022098
integrity sha512-J6SDjUgDxQj5NusnOtdFxDwN/+HWykR8GELwctJ7mdqhcyy1xEc4SRFHUXvxTp661YaVKAjfRLZ9cCqS6tn32A==
@@ -25002,11 +25010,6 @@ to-regex@^3.0.1, to-regex@^3.0.2:
2500225010
version "3.0.2"
2500325011
resolved "https://registry.yarnpkg.com/to-regex/-/to-regex-3.0.2.tgz#13cfdd9b336552f30b51f33a8ae1b42a7a7599ce"
2500425012
integrity sha512-FWtleNAtZ/Ki2qtqej2CXTOayOH9bHDQF+Q48VpWyDXjbYxA4Yz8iDB31zXOBUlOHHKidDbqGVrTUvQMPmBGBw==
25005-
dependencies:
25006-
define-property "^2.0.2"
25007-
extend-shallow "^3.0.2"
25008-
regex-not "^1.0.2"
25009-
safe-regex "^1.1.0"
2501025013

2501125014
toggle-selection@^1.0.6:
2501225015
version "1.0.6"

0 commit comments

Comments
 (0)