Skip to content

Commit 8bf6a2a

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
Refactor NewSandbox to functional component with hooks (codesandbox#1948)
1 parent f906960 commit 8bf6a2a

File tree

1 file changed

+30
-36
lines changed
  • packages/app/src/app/pages/NewSandbox

1 file changed

+30
-36
lines changed
Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
1-
import React from 'react';
1+
import Centered from '@codesandbox/common/lib/components/flex/Centered';
2+
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
3+
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
4+
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
25
import { inject } from 'mobx-react';
6+
import React, { useEffect } from 'react';
37

48
import Navigation from 'app/pages/common/Navigation';
5-
6-
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
7-
import Centered from '@codesandbox/common/lib/components/flex/Centered';
8-
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
99
import history from 'app/utils/history';
10-
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
1110

1211
import NewSandboxModal from '../Dashboard/Content/CreateNewSandbox/Modal';
1312

14-
class NewSandboxComponent extends React.PureComponent {
15-
componentDidMount() {
16-
this.props.signals.sandboxPageMounted();
17-
}
18-
19-
createSandbox = template => {
20-
history.push(sandboxUrl({ id: template.shortid }));
21-
};
22-
23-
render() {
24-
return (
25-
<MaxWidth>
26-
<Margin style={{ height: '100%' }} vertical={1.5} horizontal={1.5}>
27-
<Navigation title="New Sandbox" />
28-
29-
<Margin top={5}>
30-
<Centered horizontal vertical>
31-
<Margin style={{ maxWidth: '100%', width: 900 }} top={2}>
32-
<NewSandboxModal
33-
createSandbox={this.createSandbox}
34-
width={950}
35-
/>
36-
</Margin>
37-
</Centered>
38-
</Margin>
13+
const createSandbox = template => {
14+
history.push(sandboxUrl({ id: template.shortid }));
15+
};
16+
17+
const NewSandbox = ({ signals: { sandboxPageMounted } }) => {
18+
useEffect(() => {
19+
sandboxPageMounted();
20+
}, [sandboxPageMounted]);
21+
22+
return (
23+
<MaxWidth>
24+
<Margin horizontal={1.5} style={{ height: '100%' }} vertical={1.5}>
25+
<Navigation title="New Sandbox" />
26+
27+
<Margin top={5}>
28+
<Centered horizontal vertical>
29+
<Margin style={{ maxWidth: '100%', width: 900 }} top={2}>
30+
<NewSandboxModal createSandbox={createSandbox} width={950} />
31+
</Margin>
32+
</Centered>
3933
</Margin>
40-
</MaxWidth>
41-
);
42-
}
43-
}
34+
</Margin>
35+
</MaxWidth>
36+
);
37+
};
4438

45-
export default inject('signals')(NewSandboxComponent);
39+
export default inject('signals')(NewSandbox);

0 commit comments

Comments
 (0)