Skip to content

Commit 6aeeed7

Browse files
committed
✨ add new button on dashboard view
1 parent 4aad59a commit 6aeeed7

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

client/modules/IDE/pages/MobileIDEView.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ const MobileIDEView = (props) => {
8888
];
8989

9090

91-
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown right items={username ? navOptionsLoggedIn : navOptionsLoggedOut} />);
91+
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown
92+
items={username ? navOptionsLoggedIn : navOptionsLoggedOut}
93+
right
94+
/>);
9295

9396
return (
9497
<Screen fullscreen>

client/modules/Mobile/MobileDashboardView.jsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { useState } from 'react';
2-
import PropTypes, { string } from 'prop-types';
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
33
import styled from 'styled-components';
4+
import { useSelector } from 'react-redux';
45
import { withRouter, Link } from 'react-router';
56

67
import Screen from '../../components/mobile/MobileScreen';
@@ -14,6 +15,7 @@ import CollectionList from '../IDE/components/CollectionList';
1415
import AssetList from '../IDE/components/AssetList';
1516
import Content from './MobileViewContent';
1617
import { SketchSearchbar, CollectionSearchbar } from '../IDE/components/Searchbar';
18+
import Button from '../../common/Button';
1719

1820
const EXAMPLE_USERNAME = 'p5';
1921

@@ -26,16 +28,21 @@ const FooterTab = styled(Link)`
2628
`;
2729

2830
const Subheader = styled.div`
31+
display: flex;
32+
flex-direction: row;
33+
* { border-radius: 0px; }
2934
3035
.searchbar {
3136
display: flex;
32-
* {
33-
border-radius: 0px;
34-
}
37+
width: 100%;
3538
}
3639
.searchbar__input { width: 100%; }
3740
`;
3841

42+
const SubheaderButton = styled(Button)`
43+
border-radius: 0px !important;
44+
`;
45+
3946

4047
const FooterTabSwitcher = styled.div`
4148
display: flex;
@@ -49,23 +56,31 @@ const Panels = {
4956
assets: AssetList
5057
};
5158

52-
const renderPanel = (name, props) => (Component => (Component && <Component {...props} />))(Panels[name]);
59+
const CreatePathname = {
60+
sketches: '/mobile',
61+
collections: '/mobile/:username/collections/create',
62+
};
63+
5364

5465
const getPanel = (pathname) => {
5566
const pathparts = pathname ? pathname.split('/') : [];
5667
const matches = Object.keys(Panels).map(part => part.toLowerCase()).filter(part => pathparts.includes(part));
5768
return matches && matches.length > 0 && matches[0];
5869
};
5970

71+
const getCreatePathname = (panel, username) => (CreatePathname[panel] || '#').replace(':username', username);
6072

61-
const MobileDashboard = ({ params, location }) => {
62-
const Tabs = Object.keys(Panels);
73+
const isOwner = (user, params) => user && params && user.username === params.username;
74+
75+
const renderPanel = (name, props) => (Component => (Component && <Component {...props} />))(Panels[name]);
6376

77+
const MobileDashboard = ({ params, location }) => {
78+
const user = useSelector(state => state.user);
6479
const { username } = params;
6580
const { pathname } = location;
6681

82+
const Tabs = Object.keys(Panels);
6783
const isExamples = username === EXAMPLE_USERNAME;
68-
6984
const panel = getPanel(pathname);
7085

7186
return (
@@ -77,6 +92,7 @@ const MobileDashboard = ({ params, location }) => {
7792

7893
<Content slimheader>
7994
<Subheader>
95+
{isOwner(user, params) && <SubheaderButton to={getCreatePathname(panel, username)}>new</SubheaderButton>}
8096
{panel === Tabs[0] && <SketchSearchbar />}
8197
{panel === Tabs[1] && <CollectionSearchbar />}
8298
</Subheader>
@@ -100,6 +116,7 @@ const MobileDashboard = ({ params, location }) => {
100116
</Screen>);
101117
};
102118

119+
103120
MobileDashboard.propTypes = {
104121
location: PropTypes.shape({
105122
pathname: PropTypes.string.isRequired

0 commit comments

Comments
 (0)