add new button on dashboard view

This commit is contained in:
ghalestrilo 2020-07-31 10:21:26 -03:00
parent 4aad59a288
commit 6aeeed7ec0
2 changed files with 30 additions and 10 deletions

View file

@ -88,7 +88,10 @@ const MobileIDEView = (props) => {
]; ];
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown right items={username ? navOptionsLoggedIn : navOptionsLoggedOut} />); const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown
items={username ? navOptionsLoggedIn : navOptionsLoggedOut}
right
/>);
return ( return (
<Screen fullscreen> <Screen fullscreen>

View file

@ -1,6 +1,7 @@
import React, { useState } from 'react'; import React from 'react';
import PropTypes, { string } from 'prop-types'; import PropTypes from 'prop-types';
import styled from 'styled-components'; import styled from 'styled-components';
import { useSelector } from 'react-redux';
import { withRouter, Link } from 'react-router'; import { withRouter, Link } from 'react-router';
import Screen from '../../components/mobile/MobileScreen'; import Screen from '../../components/mobile/MobileScreen';
@ -14,6 +15,7 @@ import CollectionList from '../IDE/components/CollectionList';
import AssetList from '../IDE/components/AssetList'; import AssetList from '../IDE/components/AssetList';
import Content from './MobileViewContent'; import Content from './MobileViewContent';
import { SketchSearchbar, CollectionSearchbar } from '../IDE/components/Searchbar'; import { SketchSearchbar, CollectionSearchbar } from '../IDE/components/Searchbar';
import Button from '../../common/Button';
const EXAMPLE_USERNAME = 'p5'; const EXAMPLE_USERNAME = 'p5';
@ -26,16 +28,21 @@ const FooterTab = styled(Link)`
`; `;
const Subheader = styled.div` const Subheader = styled.div`
display: flex;
flex-direction: row;
* { border-radius: 0px; }
.searchbar { .searchbar {
display: flex; display: flex;
* { width: 100%;
border-radius: 0px;
}
} }
.searchbar__input { width: 100%; } .searchbar__input { width: 100%; }
`; `;
const SubheaderButton = styled(Button)`
border-radius: 0px !important;
`;
const FooterTabSwitcher = styled.div` const FooterTabSwitcher = styled.div`
display: flex; display: flex;
@ -49,7 +56,11 @@ const Panels = {
assets: AssetList assets: AssetList
}; };
const renderPanel = (name, props) => (Component => (Component && <Component {...props} />))(Panels[name]); const CreatePathname = {
sketches: '/mobile',
collections: '/mobile/:username/collections/create',
};
const getPanel = (pathname) => { const getPanel = (pathname) => {
const pathparts = pathname ? pathname.split('/') : []; const pathparts = pathname ? pathname.split('/') : [];
@ -57,15 +68,19 @@ const getPanel = (pathname) => {
return matches && matches.length > 0 && matches[0]; return matches && matches.length > 0 && matches[0];
}; };
const getCreatePathname = (panel, username) => (CreatePathname[panel] || '#').replace(':username', username);
const isOwner = (user, params) => user && params && user.username === params.username;
const renderPanel = (name, props) => (Component => (Component && <Component {...props} />))(Panels[name]);
const MobileDashboard = ({ params, location }) => { const MobileDashboard = ({ params, location }) => {
const Tabs = Object.keys(Panels); const user = useSelector(state => state.user);
const { username } = params; const { username } = params;
const { pathname } = location; const { pathname } = location;
const Tabs = Object.keys(Panels);
const isExamples = username === EXAMPLE_USERNAME; const isExamples = username === EXAMPLE_USERNAME;
const panel = getPanel(pathname); const panel = getPanel(pathname);
return ( return (
@ -77,6 +92,7 @@ const MobileDashboard = ({ params, location }) => {
<Content slimheader> <Content slimheader>
<Subheader> <Subheader>
{isOwner(user, params) && <SubheaderButton to={getCreatePathname(panel, username)}>new</SubheaderButton>}
{panel === Tabs[0] && <SketchSearchbar />} {panel === Tabs[0] && <SketchSearchbar />}
{panel === Tabs[1] && <CollectionSearchbar />} {panel === Tabs[1] && <CollectionSearchbar />}
</Subheader> </Subheader>
@ -100,6 +116,7 @@ const MobileDashboard = ({ params, location }) => {
</Screen>); </Screen>);
}; };
MobileDashboard.propTypes = { MobileDashboard.propTypes = {
location: PropTypes.shape({ location: PropTypes.shape({
pathname: PropTypes.string.isRequired pathname: PropTypes.string.isRequired