Skip to content

Commit 1cb881d

Browse files
committed
refactor(/app/pages/Dashboard/index): replace Cerebral with Overmind
1 parent 395c3bc commit 1cb881d

File tree

1 file changed

+69
-73
lines changed
  • packages/app/src/app/pages/Dashboard

1 file changed

+69
-73
lines changed
Lines changed: 69 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
2-
import * as React from 'react';
3-
import { inject, observer } from 'app/componentConnectors';
2+
import React, { useState, useEffect } from 'react';
3+
import { useOvermind } from 'app/overmind';
44
import RightIcon from 'react-icons/lib/md/keyboard-arrow-right';
55
import LeftIcon from 'react-icons/lib/md/keyboard-arrow-left';
66
import { withRouter } from 'react-router-dom';
@@ -22,89 +22,85 @@ import {
2222
OffsettedLogo,
2323
} from './elements';
2424

25-
class Dashboard extends React.Component {
26-
state = {
27-
showSidebar: false,
28-
};
25+
const Dashboard = props => {
26+
const [showSidebar, setShowSidebar] = useState(false);
2927

30-
componentDidMount() {
31-
this.props.signals.dashboard.dashboardMounted();
32-
}
28+
const {
29+
state: { hasLogIn },
30+
actions: { dashboard },
31+
} = useOvermind();
3332

34-
componentWillUnmount() {
35-
// Reset store so new visits get fresh data
36-
client.resetStore();
37-
}
33+
useEffect(() => {
34+
dashboard.dashboardMounted();
35+
return () => {
36+
// Reset store so new visits get fresh data
37+
client.resetStore();
38+
};
39+
}, [dashboard]);
3840

39-
onRouteChange = () => {
40-
this.setState({ showSidebar: false });
41+
const onRouteChange = () => {
42+
setShowSidebar(false);
4143
};
4244

43-
toggleSidebar = () => {
44-
this.setState(({ showSidebar }) => ({ showSidebar: !showSidebar }));
45+
const toggleSidebar = () => {
46+
setShowSidebar(!showSidebar);
4547
};
4648

47-
render() {
48-
const {
49-
store: { hasLogIn },
50-
history,
51-
} = this.props;
52-
const { showSidebar } = this.state;
53-
54-
history.listen(({ state }) => {
55-
if (!!state && state.from === 'sandboxSearchFocused') {
56-
return;
57-
}
58-
59-
this.onRouteChange();
60-
});
61-
62-
let DashboardContent = (
63-
<>
64-
<Sidebar active={showSidebar}>
65-
<SidebarContents />
66-
<ShowSidebarButton onClick={this.toggleSidebar}>
67-
{showSidebar ? (
68-
<LeftIcon style={{ color: 'white' }} />
69-
) : (
70-
<RightIcon style={{ color: 'white' }} />
71-
)}
72-
</ShowSidebarButton>
73-
</Sidebar>
74-
75-
<ContentContainer>
76-
<Content />
77-
</ContentContainer>
78-
</>
79-
);
49+
const { history } = props;
8050

81-
if (!hasLogIn) {
82-
DashboardContent = (
83-
<Container>
84-
<Centered>
85-
<LoggedInContainer>
86-
<OffsettedLogo />
87-
<LoggedInTitle>Sign in to CodeSandbox</LoggedInTitle>
88-
89-
<SignInButton big style={{ fontSize: '1rem' }} />
90-
</LoggedInContainer>
91-
</Centered>
92-
</Container>
93-
);
51+
history.listen(({ state }) => {
52+
if (!!state && state.from === 'sandboxSearchFocused') {
53+
return;
9454
}
9555

96-
return (
56+
onRouteChange();
57+
});
58+
59+
let DashboardContent = (
60+
<>
61+
<Sidebar active={showSidebar}>
62+
<SidebarContents />
63+
<ShowSidebarButton onClick={toggleSidebar}>
64+
{showSidebar ? (
65+
<LeftIcon style={{ color: 'white' }} />
66+
) : (
67+
<RightIcon style={{ color: 'white' }} />
68+
)}
69+
</ShowSidebarButton>
70+
</Sidebar>
71+
72+
<ContentContainer>
73+
<Content />
74+
</ContentContainer>
75+
</>
76+
);
77+
78+
if (!hasLogIn) {
79+
DashboardContent = (
9780
<Container>
98-
<NavigationContainer>
99-
<Navigation searchNoInput title="Dashboard" />
100-
</NavigationContainer>
101-
102-
<div style={{ display: 'flex', overflow: 'hidden' }}>
103-
{DashboardContent}
104-
</div>
81+
<Centered>
82+
<LoggedInContainer>
83+
<OffsettedLogo />
84+
<LoggedInTitle>Sign in to CodeSandbox</LoggedInTitle>
85+
86+
<SignInButton big style={{ fontSize: '1rem' }} />
87+
</LoggedInContainer>
88+
</Centered>
10589
</Container>
10690
);
10791
}
108-
}
10992

110-
export default inject('store', 'signals')(withRouter(observer(Dashboard)));
93+
return (
94+
<Container>
95+
<NavigationContainer>
96+
<Navigation searchNoInput title="Dashboard" />
97+
</NavigationContainer>
98+
99+
<div style={{ display: 'flex', overflow: 'hidden' }}>
100+
{DashboardContent}
101+
</div>
102+
</Container>
103+
);
104+
};
105+
106+
export default withRouter(Dashboard);

0 commit comments

Comments
 (0)