Skip to content

Commit 47240c3

Browse files
committed
🔨 Switch SelectSandboxModal to use useOvermind
1 parent ce2da4f commit 47240c3

File tree

8 files changed

+86
-79
lines changed

8 files changed

+86
-79
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ export const selectSandboxClicked: AsyncAction = async ({ state, effects }) => {
8383
}
8484
};
8585

86-
export const newSandboxShowcaseSelected: AsyncAction<{
87-
id: string;
88-
}> = async ({ state, effects }, { id }) => {
86+
export const newSandboxShowcaseSelected: AsyncAction<string> = async (
87+
{ state, effects },
88+
id
89+
) => {
8990
state.profile.showSelectSandboxModal = false;
9091
state.profile.profiles[
9192
state.profile.currentProfileId

‎packages/app/src/app/pages/common/Modals/SelectSandboxModal/Sandbox/elements.js‎

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import styled, { css } from 'styled-components';
2+
3+
export const Button = styled.button<{ active: boolean }>`
4+
${({ active }) => css`
5+
display: flex;
6+
justify-content: space-between;
7+
transition: 0.3s ease all;
8+
width: 100%;
9+
height: 100%;
10+
outline: none;
11+
border: none;
12+
background-color: ${active ? '#eeeeee' : 'white'};
13+
padding: 1rem;
14+
color: rgba(0, 0, 0, 0.9);
15+
box-sizing: border-box;
16+
border-bottom: 1px solid #dddddd;
17+
text-align: left;
18+
${active &&
19+
css`
20+
font-weight: 600;
21+
`};
22+
cursor: ${active ? 'default' : 'pointer'};
23+
24+
&:hover {
25+
background-color: #eeeeee;
26+
}
27+
`};
28+
`;
29+
30+
export const Date = styled.div`
31+
color: rgba(0, 0, 0, 0.6);
32+
`;

‎packages/app/src/app/pages/common/Modals/SelectSandboxModal/Sandbox/index.js‎

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { UserSandbox } from '@codesandbox/common/lib/types';
2+
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
3+
import React, { FunctionComponent } from 'react';
4+
import { format } from 'date-fns';
5+
import { zonedTimeToUtc } from 'date-fns-tz';
6+
7+
import { useOvermind } from 'app/overmind';
8+
9+
import { Button, Date } from './elements';
10+
11+
type Props = {
12+
sandbox: UserSandbox;
13+
};
14+
export const Sandbox: FunctionComponent<Props> = ({ sandbox }) => {
15+
const {
16+
actions: {
17+
profile: { newSandboxShowcaseSelected },
18+
},
19+
state: {
20+
profile: { showcasedSandbox },
21+
},
22+
} = useOvermind();
23+
const active = sandbox.id === showcasedSandbox.id;
24+
25+
return (
26+
<Button
27+
active={active}
28+
onClick={() => newSandboxShowcaseSelected(sandbox.id)}
29+
>
30+
<div>
31+
{getSandboxName(sandbox)}
32+
33+
{active && ' (Selected)'}
34+
</div>
35+
36+
<Date>
37+
{format(zonedTimeToUtc(sandbox.insertedAt, 'Etc/UTC'), 'MMM dd, yyyy')}
38+
</Date>
39+
</Button>
40+
);
41+
};
File renamed without changes.
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
11
import React, { FunctionComponent } from 'react';
2+
23
import { useOvermind } from 'app/overmind';
3-
import { Padding } from './elements';
44

5-
import Sandbox from './Sandbox';
5+
import { Padding } from './elements';
6+
import { Sandbox } from './Sandbox';
67

78
export const SelectSandboxModal: FunctionComponent = () => {
89
const {
910
state: {
10-
profile: { isLoadingSandboxes, showcasedSandbox, userSandboxes },
11-
},
12-
actions: {
13-
profile: { newSandboxShowcaseSelected },
11+
profile: { isLoadingSandboxes, userSandboxes },
1412
},
1513
} = useOvermind();
1614

1715
if (isLoadingSandboxes) {
1816
return <Padding>Loading sandboxes...</Padding>;
1917
}
2018

21-
const currentShowcasedSandboxId = showcasedSandbox && showcasedSandbox.id;
22-
2319
return (
2420
<div>
25-
{userSandboxes
26-
.filter(x => x)
27-
.map(sandbox => (
28-
<Sandbox
29-
active={sandbox.id === currentShowcasedSandboxId}
30-
key={sandbox.id}
31-
sandbox={sandbox}
32-
setShowcasedSandbox={id => newSandboxShowcaseSelected({ id })}
33-
/>
34-
))}
21+
{userSandboxes.filter(Boolean).map(sandbox => (
22+
<Sandbox key={sandbox.id} sandbox={sandbox} />
23+
))}
3524
</div>
3625
);
3726
};

‎packages/common/src/utils/get-sandbox-name.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export const getSandboxName = ({
44
alias,
55
id,
66
title,
7-
}: Pick<Sandbox, 'alias' | 'id' | 'title'>) => title || alias || id;
7+
}: Partial<Pick<Sandbox, 'alias'>> & Pick<Sandbox, 'id' | 'title'>) =>
8+
title || alias || id;

0 commit comments

Comments
 (0)