Skip to content

Commit 601d1f4

Browse files
🔨 Switch Profile/Showcase to use useOvermind (#3409)
1 parent 0394eb3 commit 601d1f4

File tree

7 files changed

+106
-66
lines changed

7 files changed

+106
-66
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Centered from '@codesandbox/common/lib/components/flex/Centered';
2+
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
3+
import React, { FunctionComponent } from 'react';
4+
5+
import { ErrorTitle } from './elements';
6+
7+
export const LoadingSandbox: FunctionComponent = () => (
8+
<Centered horizontal vertical>
9+
<Margin top={4}>
10+
<ErrorTitle>Loading showcased sandbox...</ErrorTitle>
11+
</Margin>
12+
</Centered>
13+
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { FunctionComponent } from 'react';
2+
import Centered from '@codesandbox/common/lib/components/flex/Centered';
3+
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
4+
5+
import { useOvermind } from 'app/overmind';
6+
7+
import { ErrorTitle } from './elements';
8+
9+
export const NoSandboxAvailable: FunctionComponent = () => {
10+
const {
11+
state: {
12+
profile: { isProfileCurrentUser },
13+
},
14+
} = useOvermind();
15+
16+
return (
17+
<Centered horizontal vertical>
18+
<Margin top={4}>
19+
<ErrorTitle>
20+
{`${
21+
isProfileCurrentUser ? `You don't` : `This user doesn't`
22+
} have any sandboxes yet`}
23+
</ErrorTitle>
24+
</Margin>
25+
</Centered>
26+
);
27+
};

‎packages/app/src/app/pages/Profile/Showcase/SandboxInfo/elements.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export const Description = styled.p`
3939
color: rgba(255, 255, 255, 0.8);
4040
`;
4141

42+
export const DescriptionContainer = styled.div`
43+
flex: 6;
44+
`;
45+
4246
export const Stats = styled.div`
4347
position: relative;
4448
display: flex;

‎packages/app/src/app/pages/Profile/Showcase/SandboxInfo/index.tsx‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Row from '@codesandbox/common/lib/components/flex/Row';
2-
import { Sandbox } from '@codesandbox/common/lib/types';
32
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
43
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
54
import React, { FunctionComponent } from 'react';
@@ -10,47 +9,56 @@ import { useOvermind } from 'app/overmind';
109
import {
1110
Container,
1211
Description,
12+
DescriptionContainer,
1313
Like,
1414
PlayButtonContainer,
1515
Stats,
1616
Title,
1717
} from './elements';
1818
import SvgButton from './play-button.svg';
1919

20-
type Props = {
21-
sandbox: Sandbox;
22-
};
23-
export const SandboxInfo: FunctionComponent<Props> = ({ sandbox }) => {
20+
export const SandboxInfo: FunctionComponent = () => {
2421
const {
25-
state: { isLoggedIn },
22+
state: {
23+
profile: {
24+
showcasedSandbox,
25+
showcasedSandbox: {
26+
alias,
27+
description,
28+
forkCount,
29+
id,
30+
likeCount,
31+
viewCount,
32+
},
33+
},
34+
isLoggedIn,
35+
},
2636
} = useOvermind();
2737

2838
return (
2939
<Container>
3040
<Row alignItems="center">
3141
<Title>
32-
{getSandboxName(sandbox)} {''}
33-
{isLoggedIn ? <Like sandbox={sandbox} /> : null}
42+
{getSandboxName(showcasedSandbox)} {''}
43+
{isLoggedIn ? <Like sandbox={showcasedSandbox} /> : null}
3444
</Title>
3545
</Row>
3646

3747
<Row alignItems="flex-start">
38-
<div style={{ flex: 6 }}>
39-
<Description>{sandbox.description}</Description>
40-
</div>
48+
<DescriptionContainer>
49+
<Description>{description}</Description>
50+
</DescriptionContainer>
4151

4252
<Stats>
43-
<PlayButtonContainer
44-
to={sandboxUrl({ id: sandbox.id, alias: sandbox.alias })}
45-
>
53+
<PlayButtonContainer to={sandboxUrl({ alias, id })}>
4654
<img alt="edit" src={SvgButton} />
4755
</PlayButtonContainer>
4856

49-
<Stat name="likes" count={sandbox.likeCount} />
57+
<Stat name="likes" count={likeCount} />
5058

51-
<Stat name="views" count={sandbox.viewCount} />
59+
<Stat name="views" count={viewCount} />
5260

53-
<Stat name="forks" count={sandbox.forkCount} />
61+
<Stat name="forks" count={forkCount} />
5462
</Stats>
5563
</Row>
5664
</Container>

‎packages/app/src/app/pages/Profile/Showcase/elements.js‎

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import styled, { css } from 'styled-components';
2+
3+
export const ErrorTitle = styled.div`
4+
${({ theme }) => css`
5+
font-size: 1.25rem;
6+
color: ${theme.light ? 'rgba(0, 0, 0, 0.7)' : 'rgba(255, 255, 255, 0.7)'};
7+
`};
8+
`;
9+
10+
export const SandboxInfoContainer = styled.div`
11+
flex: 1;
12+
`;
13+
14+
export const ShowcasePreviewContainer = styled.div`
15+
flex: 2;
16+
`;

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

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,55 @@
11
import React, { FunctionComponent } from 'react';
2-
import { useOvermind } from 'app/overmind';
3-
42
import Column from '@codesandbox/common/lib/components/flex/Column';
5-
import Centered from '@codesandbox/common/lib/components/flex/Centered';
63
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
74
import { Button } from '@codesandbox/common/lib/components/Button';
85

9-
import { SandboxInfo } from './SandboxInfo';
6+
import { useOvermind } from 'app/overmind';
7+
108
import ShowcasePreview from '../../common/ShowcasePreview';
119

12-
import { ErrorTitle } from './elements';
10+
import { SandboxInfoContainer, ShowcasePreviewContainer } from './elements';
11+
import { LoadingSandbox } from './LoadingSandbox';
12+
import { NoSandboxAvailable } from './NoSandboxAvailable';
13+
import { SandboxInfo } from './SandboxInfo';
1314

1415
export const Showcase: FunctionComponent = () => {
1516
const {
16-
state: {
17-
profile,
18-
profile: { isLoadingProfile },
19-
preferences: { settings },
20-
},
2117
actions: {
2218
profile: { selectSandboxClicked },
2319
},
20+
state: {
21+
preferences: { settings },
22+
profile: { isLoadingProfile, isProfileCurrentUser, showcasedSandbox },
23+
},
2424
} = useOvermind();
25-
const sandbox = profile.showcasedSandbox;
26-
const isCurrentUser = profile.isProfileCurrentUser;
27-
28-
const openModal = () => {
29-
selectSandboxClicked();
30-
};
3125

3226
if (isLoadingProfile) {
33-
return (
34-
<Centered vertical horizontal>
35-
<Margin top={4}>
36-
<ErrorTitle>Loading showcased sandbox...</ErrorTitle>
37-
</Margin>
38-
</Centered>
39-
);
27+
return <LoadingSandbox />;
4028
}
4129

42-
if (!sandbox) {
43-
return (
44-
<Centered vertical horizontal>
45-
<Margin top={4}>
46-
<ErrorTitle>
47-
{isCurrentUser ? "You don't" : "This user doesn't"} have any
48-
sandboxes yet
49-
</ErrorTitle>
50-
</Margin>
51-
</Centered>
52-
);
30+
if (!showcasedSandbox) {
31+
return <NoSandboxAvailable />;
5332
}
5433

5534
return (
5635
<Column alignItems="center">
5736
<Margin top={1}>
58-
{isCurrentUser && (
59-
<Button small onClick={openModal}>
37+
{isProfileCurrentUser && (
38+
<Button onClick={() => selectSandboxClicked()} small>
6039
Change Sandbox
6140
</Button>
6241
)}
6342
</Margin>
6443

6544
<Margin top={2} style={{ width: '100%' }}>
6645
<Column alignItems="initial">
67-
<div style={{ flex: 2 }}>
68-
<ShowcasePreview sandbox={sandbox} settings={settings} />
69-
</div>
46+
<ShowcasePreviewContainer>
47+
<ShowcasePreview sandbox={showcasedSandbox} settings={settings} />
48+
</ShowcasePreviewContainer>
7049

71-
<div style={{ flex: 1 }}>
72-
<SandboxInfo sandbox={sandbox} />
73-
</div>
50+
<SandboxInfoContainer>
51+
<SandboxInfo />
52+
</SandboxInfoContainer>
7453
</Column>
7554
</Margin>
7655
</Column>

0 commit comments

Comments
 (0)