Skip to content

Commit ad730a0

Browse files
committed
Merge branch 'lusan-dashboard-sandbox-indexpage'
2 parents b0afbe8 + 3e423b9 commit ad730a0

File tree

4 files changed

+133
-157
lines changed

4 files changed

+133
-157
lines changed

packages/app/src/app/pages/Dashboard/Sidebar/elements.js renamed to packages/app/src/app/pages/Dashboard/Sidebar/elements.ts

File renamed without changes.

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

Lines changed: 0 additions & 152 deletions
This file was deleted.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import React from 'react';
2+
import history from 'app/utils/history';
3+
import { useOvermind } from 'app/overmind';
4+
import { withRouter, Route } from 'react-router-dom';
5+
import { Query } from 'react-apollo';
6+
import Input from '@codesandbox/common/lib/components/Input';
7+
import { Button } from '@codesandbox/common/lib/components/Button';
8+
import PeopleIcon from 'react-icons/lib/md/people';
9+
import { teamOverviewUrl } from '@codesandbox/common/lib/utils/url-generator';
10+
import DashboardIcon from '-!svg-react-loader!@codesandbox/common/lib/icons/dashboard.svg';
11+
12+
import { Item } from './Item';
13+
import { SandboxesItem } from './SandboxesItem';
14+
import { TrashItem } from './TrashItem';
15+
import { Items, CategoryHeader, SidebarStyled, InputWrapper } from './elements';
16+
import { TEAMS_QUERY } from '../queries';
17+
import { TemplateItem } from './TemplateItem';
18+
19+
const SidebarComponent = () => {
20+
const {
21+
state: { dashboard: dashboardState },
22+
actions: { dashboard: dashboardAction },
23+
} = useOvermind();
24+
25+
const handleSearchFocus = () => {
26+
history.push('/dashboard/search', { from: 'sandboxSearchFocused' });
27+
};
28+
29+
const handleSearchChange: React.ChangeEventHandler<HTMLInputElement> = e => {
30+
dashboardAction.searchChanged({ search: e.target.value });
31+
};
32+
33+
return (
34+
<SidebarStyled>
35+
<InputWrapper>
36+
<Input
37+
onFocus={handleSearchFocus}
38+
block
39+
value={dashboardState.filters.search}
40+
onChange={handleSearchChange}
41+
placeholder="Search my sandboxes"
42+
/>
43+
</InputWrapper>
44+
45+
<Route
46+
path={[
47+
'/dashboard/sandboxes/:path*',
48+
'/dashboard/teams/:teamId/sandboxes/:path*',
49+
'/',
50+
]}
51+
>
52+
{({ location, match }) => {
53+
const testRegex = /\/dashboard.*?sandboxes/;
54+
55+
const path = location.pathname.replace(testRegex, '');
56+
const currentTeamId = match ? match.params.teamId : undefined;
57+
58+
return (
59+
<>
60+
<Items style={{ marginBottom: '1rem' }}>
61+
<Item
62+
Icon={DashboardIcon}
63+
path="/dashboard/recent"
64+
name="Overview"
65+
/>
66+
67+
<SandboxesItem
68+
selectedSandboxes={dashboardState.selectedSandboxes}
69+
currentPath={path}
70+
currentTeamId={currentTeamId}
71+
openByDefault
72+
/>
73+
74+
<TemplateItem currentPath={path} />
75+
76+
<TrashItem currentPath={path} />
77+
</Items>
78+
79+
<Query query={TEAMS_QUERY}>
80+
{({ loading, data, error }) => {
81+
if (loading || error || !data.me || !(data && data.me)) {
82+
return null;
83+
}
84+
85+
const { teams = [] } = data.me;
86+
87+
return teams.map(({ id, name }) => (
88+
<div key={id}>
89+
<Items>
90+
<CategoryHeader>{name}</CategoryHeader>
91+
<Item
92+
Icon={PeopleIcon}
93+
path={teamOverviewUrl(id)}
94+
name="Team Overview"
95+
/>
96+
97+
<SandboxesItem
98+
selectedSandboxes={dashboardState.selectedSandboxes}
99+
currentPath={path}
100+
currentTeamId={currentTeamId}
101+
teamId={id}
102+
/>
103+
104+
<TemplateItem currentPath={path} teamId={id} />
105+
</Items>
106+
</div>
107+
));
108+
}}
109+
</Query>
110+
</>
111+
);
112+
}}
113+
</Route>
114+
115+
<div style={{ margin: '2rem', fontSize: '.875rem' }}>
116+
<Button
117+
style={{ display: 'block' }}
118+
to="/dashboard/teams/new"
119+
small
120+
block
121+
>
122+
Create Team
123+
</Button>
124+
</div>
125+
</SidebarStyled>
126+
);
127+
};
128+
export const Sidebar = withRouter(SidebarComponent);

packages/app/src/app/pages/Dashboard/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { Navigation } from 'app/pages/common/Navigation';
77
import { signInPageUrl } from '@codesandbox/common/lib/utils/url-generator';
88
import { client } from 'app/graphql/client';
99

10-
import SidebarContents from './Sidebar';
10+
import { Sidebar } from './Sidebar';
1111
import Content from './Content';
1212
import {
1313
Container,
1414
Content as ContentContainer,
15-
Sidebar,
15+
Sidebar as SidebarStyled,
1616
ShowSidebarButton,
1717
} from './elements';
1818

@@ -52,16 +52,16 @@ const Dashboard = props => {
5252

5353
const DashboardContent = (
5454
<>
55-
<Sidebar active={showSidebar}>
56-
<SidebarContents />
55+
<SidebarStyled active={showSidebar}>
56+
<Sidebar />
5757
<ShowSidebarButton onClick={toggleSidebar}>
5858
{showSidebar ? (
5959
<LeftIcon style={{ color: 'white' }} />
6060
) : (
6161
<RightIcon style={{ color: 'white' }} />
6262
)}
6363
</ShowSidebarButton>
64-
</Sidebar>
64+
</SidebarStyled>
6565

6666
<ContentContainer>
6767
<Content />

0 commit comments

Comments
 (0)