Skip to content

Commit d9ad79c

Browse files
armujahidSaraVieira
authored andcommitted
🔨 Refactor(/app/pages/Dashboard/index): replace Cerebral with… (codesandbox#2833)
* refactor(/app/pages/Dashboard/index): replace Cerebral with Overmind * fix: typecheck error in /app/pages/Dashboard/index * refactor(/app/pages/Dashboard/index): remove unnecessary @ts-check * fix: typecheck error in /app/pages/Dashboard/index
1 parent 8f59b5a commit d9ad79c

File tree

4 files changed

+107
-111
lines changed

4 files changed

+107
-111
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Action, AsyncAction } from 'app/overmind';
22
import { withLoadApp } from 'app/overmind/factories';
33
import { OrderBy } from './state';
44

5-
export const dashboardMounted = withLoadApp();
5+
export const dashboardMounted: AsyncAction = withLoadApp();
66

77
export const sandboxesSelected: Action<{
88
sandboxIds: string[];

‎packages/app/src/app/pages/Dashboard/index.js‎

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import React, { useState, useEffect } from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
import RightIcon from 'react-icons/lib/md/keyboard-arrow-right';
4+
import LeftIcon from 'react-icons/lib/md/keyboard-arrow-left';
5+
import { withRouter } from 'react-router-dom';
6+
import { Navigation } from 'app/pages/common/Navigation';
7+
import { SignInButton } from 'app/pages/common/SignInButton';
8+
import { client } from 'app/graphql/client';
9+
10+
import SidebarContents from './Sidebar';
11+
import Content from './Content';
12+
import {
13+
Container,
14+
Centered,
15+
Content as ContentContainer,
16+
LoggedInContainer,
17+
LoggedInTitle,
18+
Sidebar,
19+
NavigationContainer,
20+
ShowSidebarButton,
21+
OffsettedLogo,
22+
} from './elements';
23+
24+
const Dashboard = props => {
25+
const [showSidebar, setShowSidebar] = useState(false);
26+
27+
const {
28+
state: { hasLogIn },
29+
actions: { dashboard },
30+
} = useOvermind();
31+
32+
useEffect(() => {
33+
dashboard.dashboardMounted();
34+
return () => {
35+
// Reset store so new visits get fresh data
36+
client.resetStore();
37+
};
38+
}, [dashboard]);
39+
40+
const onRouteChange = () => {
41+
setShowSidebar(false);
42+
};
43+
44+
const toggleSidebar = () => {
45+
setShowSidebar(!showSidebar);
46+
};
47+
48+
const { history } = props;
49+
50+
history.listen(({ state }) => {
51+
if (!!state && state.from === 'sandboxSearchFocused') {
52+
return;
53+
}
54+
55+
onRouteChange();
56+
});
57+
58+
let DashboardContent = (
59+
<>
60+
<Sidebar active={showSidebar}>
61+
<SidebarContents />
62+
<ShowSidebarButton onClick={toggleSidebar}>
63+
{showSidebar ? (
64+
<LeftIcon style={{ color: 'white' }} />
65+
) : (
66+
<RightIcon style={{ color: 'white' }} />
67+
)}
68+
</ShowSidebarButton>
69+
</Sidebar>
70+
71+
<ContentContainer>
72+
<Content />
73+
</ContentContainer>
74+
</>
75+
);
76+
77+
if (!hasLogIn) {
78+
DashboardContent = (
79+
<Container>
80+
<Centered>
81+
<LoggedInContainer>
82+
<OffsettedLogo />
83+
<LoggedInTitle>Sign in to CodeSandbox</LoggedInTitle>
84+
85+
<SignInButton big style={{ fontSize: '1rem' }} />
86+
</LoggedInContainer>
87+
</Centered>
88+
</Container>
89+
);
90+
}
91+
92+
return (
93+
<Container>
94+
<NavigationContainer>
95+
<Navigation searchNoInput title="Dashboard" />
96+
</NavigationContainer>
97+
98+
<div style={{ display: 'flex', overflow: 'hidden' }}>
99+
{DashboardContent}
100+
</div>
101+
</Container>
102+
);
103+
};
104+
105+
export default withRouter(Dashboard);

‎packages/common/src/components/Button/index.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LinkButton, AButton, Button } from './elements';
44
export type Props = {
55
to?: string;
66
href?: string;
7+
big?: boolean;
78
small?: boolean;
89
style?: React.CSSProperties;
910
block?: boolean;

0 commit comments

Comments
 (0)