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 , Redirect } from 'react-router-dom' ;
6- import { Navigation } from 'app/pages/common/Navigation' ;
71import { signInPageUrl } from '@codesandbox/common/lib/utils/url-generator' ;
2+ import React , { useState , useEffect , FunctionComponent } from 'react' ;
3+ import { withRouter , Redirect , RouteComponentProps } from 'react-router-dom' ;
4+
85import { client } from 'app/graphql/client' ;
6+ import { useOvermind } from 'app/overmind' ;
7+ import { Navigation } from 'app/pages/common/Navigation' ;
98
10- import { Sidebar } from './Sidebar' ;
119import Content from './Content' ;
1210import {
1311 Container ,
14- Content as ContentContainer ,
15- Sidebar as SidebarStyled ,
12+ ContentContainer ,
13+ LeftIcon ,
14+ RightIcon ,
15+ SidebarContainer ,
1616 ShowSidebarButton ,
1717} from './elements' ;
18+ import { Sidebar } from './Sidebar' ;
1819
19- const Dashboard = props => {
20- const [ showSidebar , setShowSidebar ] = useState ( false ) ;
21-
20+ type Props = RouteComponentProps ;
21+ const DashboardComponent : FunctionComponent < Props > = ( { history } ) => {
2222 const {
23+ actions : {
24+ dashboard : { dashboardMounted } ,
25+ } ,
2326 state : { hasLogIn } ,
24- actions : { dashboard } ,
2527 } = useOvermind ( ) ;
28+ const [ showSidebar , setShowSidebar ] = useState ( false ) ;
2629
2730 useEffect ( ( ) => {
28- dashboard . dashboardMounted ( ) ;
29- return ( ) => {
30- // Reset store so new visits get fresh data
31- client . resetStore ( ) ;
32- } ;
33- } , [ dashboard ] ) ;
31+ dashboardMounted ( ) ;
3432
35- const onRouteChange = ( ) => {
36- setShowSidebar ( false ) ;
37- } ;
38-
39- const toggleSidebar = ( ) => {
40- setShowSidebar ( ! showSidebar ) ;
41- } ;
42-
43- const { history } = props ;
33+ // Reset store so new visits get fresh data
34+ return ( ) => client . resetStore ( ) ;
35+ } , [ dashboardMounted ] ) ;
4436
4537 history . listen ( ( { state } ) => {
46- if ( ! ! state && state . from === 'sandboxSearchFocused' ) {
38+ if ( state ? .from === 'sandboxSearchFocused' ) {
4739 return ;
4840 }
4941
50- onRouteChange ( ) ;
42+ setShowSidebar ( false ) ;
5143 } ) ;
5244
53- const DashboardContent = (
54- < >
55- < SidebarStyled active = { showSidebar } >
56- < Sidebar />
57- < ShowSidebarButton onClick = { toggleSidebar } >
58- { showSidebar ? (
59- < LeftIcon style = { { color : 'white' } } />
60- ) : (
61- < RightIcon style = { { color : 'white' } } />
62- ) }
63- </ ShowSidebarButton >
64- </ SidebarStyled >
65-
66- < ContentContainer >
67- < Content />
68- </ ContentContainer >
69- </ >
70- ) ;
71-
7245 if ( ! hasLogIn ) {
7346 return < Redirect to = { signInPageUrl ( ) } /> ;
7447 }
@@ -78,10 +51,20 @@ const Dashboard = props => {
7851 < Navigation float searchNoInput title = "Dashboard" />
7952
8053 < div style = { { display : 'flex' , overflow : 'hidden' } } >
81- { DashboardContent }
54+ < SidebarContainer active = { showSidebar } >
55+ < Sidebar />
56+
57+ < ShowSidebarButton onClick = { ( ) => setShowSidebar ( show => ! show ) } >
58+ { showSidebar ? < LeftIcon /> : < RightIcon /> }
59+ </ ShowSidebarButton >
60+ </ SidebarContainer >
61+
62+ < ContentContainer >
63+ < Content />
64+ </ ContentContainer >
8265 </ div >
8366 </ Container >
8467 ) ;
8568} ;
8669
87- export default withRouter ( Dashboard ) ;
70+ export const Dashboard = withRouter ( DashboardComponent ) ;
0 commit comments