Skip to content

Commit 012220f

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch Profile to use useOvermind (#3352)
1 parent c7002dc commit 012220f

File tree

4 files changed

+60
-54
lines changed

4 files changed

+60
-54
lines changed

‎packages/app/src/app/overmind/namespaces/profile/actions.ts‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ import { Sandbox } from '@codesandbox/common/lib/types';
22
import { Action, AsyncAction } from 'app/overmind';
33
import { withLoadApp } from 'app/overmind/factories';
44

5-
export const profileMounted: AsyncAction<{
6-
username: string;
7-
}> = withLoadApp(async ({ state, effects }, { username }) => {
8-
state.profile.isLoadingProfile = true;
9-
state.profile.notFound = false;
10-
11-
const profile = await effects.api.getProfile(username);
12-
13-
state.profile.profiles[profile.id] = profile;
14-
state.profile.currentProfileId = profile.id;
5+
export const profileMounted: AsyncAction<string> = withLoadApp(
6+
async ({ effects, state }, username) => {
7+
state.profile.isLoadingProfile = true;
8+
state.profile.notFound = false;
9+
10+
const profile = await effects.api.getProfile(username);
11+
12+
state.profile.profiles[profile.id] = profile;
13+
state.profile.currentProfileId = profile.id;
14+
15+
if (
16+
profile.showcasedSandboxShortid &&
17+
!state.editor.sandboxes[profile.showcasedSandboxShortid]
18+
) {
19+
state.editor.sandboxes[
20+
profile.showcasedSandboxShortid
21+
] = await effects.api.getSandbox(profile.showcasedSandboxShortid);
22+
}
1523

16-
if (
17-
profile.showcasedSandboxShortid &&
18-
!state.editor.sandboxes[profile.showcasedSandboxShortid]
19-
) {
20-
state.editor.sandboxes[
21-
profile.showcasedSandboxShortid
22-
] = await effects.api.getSandbox(profile.showcasedSandboxShortid);
24+
state.profile.isLoadingProfile = false;
2325
}
24-
25-
state.profile.isLoadingProfile = false;
26-
});
26+
);
2727

2828
export const sandboxesPageChanged: AsyncAction<{
2929
page: number;

‎packages/app/src/app/pages/Profile/elements.js‎ renamed to ‎packages/app/src/app/pages/Profile/elements.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import styled from 'styled-components';
21
import Fullscreen from '@codesandbox/common/lib/components/flex/Fullscreen';
2+
import MarginBase from '@codesandbox/common/lib/components/spacing/Margin';
3+
import styled, { css } from 'styled-components';
34

45
export const Container = styled(Fullscreen)`
56
color: white;
@@ -11,6 +12,12 @@ export const Container = styled(Fullscreen)`
1112
`;
1213

1314
export const Content = styled(Fullscreen)`
14-
border-top: 1px solid ${props => props.theme.background3};
15-
flex: 0 0 70px;
15+
${({ theme }) => css`
16+
border-top: 1px solid ${theme.background3};
17+
flex: 0 0 70px;
18+
`};
19+
`;
20+
21+
export const Margin = styled(MarginBase)`
22+
min-height: 60vh;
1623
`;
Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,90 @@
11
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
2-
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
32
import {
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+
710
import { useOvermind } from 'app/overmind';
811
import { 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';
1414
import Header from './Header';
1515
import Navigation from './Navigation';
1616
import { Sandboxes } from './Sandboxes';
1717
import { 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;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ const NotFound = Loadable(() =>
4040
import(/* webpackChunkName: 'page-not-found' */ './common/NotFound')
4141
);
4242
const Profile = Loadable(() =>
43-
import(/* webpackChunkName: 'page-profile' */ './Profile')
43+
import(/* webpackChunkName: 'page-profile' */ './Profile').then(module => ({
44+
default: module.Profile,
45+
}))
4446
);
4547
const Search = Loadable(() =>
4648
import(/* webpackChunkName: 'page-search' */ './Search').then(module => ({

0 commit comments

Comments
 (0)