2020-07-31 15:21:26 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-07-24 23:43:07 +02:00
|
|
|
import styled from 'styled-components';
|
2020-07-31 15:21:26 +02:00
|
|
|
import { useSelector } from 'react-redux';
|
2020-07-31 14:04:48 +02:00
|
|
|
import { withRouter, Link } from 'react-router';
|
2020-07-30 20:40:43 +02:00
|
|
|
|
2020-07-24 23:11:10 +02:00
|
|
|
import Screen from '../../components/mobile/MobileScreen';
|
|
|
|
import Header from '../../components/mobile/Header';
|
|
|
|
import IconButton from '../../components/mobile/IconButton';
|
|
|
|
import { ExitIcon } from '../../common/icons';
|
2020-07-24 23:43:07 +02:00
|
|
|
import Footer from '../../components/mobile/Footer';
|
|
|
|
import { prop, remSize } from '../../theme';
|
2020-07-28 16:33:38 +02:00
|
|
|
import SketchList from '../IDE/components/SketchList';
|
|
|
|
import CollectionList from '../IDE/components/CollectionList';
|
|
|
|
import AssetList from '../IDE/components/AssetList';
|
|
|
|
import Content from './MobileViewContent';
|
2020-07-31 14:09:35 +02:00
|
|
|
import { SketchSearchbar, CollectionSearchbar } from '../IDE/components/Searchbar';
|
2020-07-31 15:21:26 +02:00
|
|
|
import Button from '../../common/Button';
|
2020-07-28 22:46:22 +02:00
|
|
|
|
|
|
|
const EXAMPLE_USERNAME = 'p5';
|
2020-07-24 23:11:10 +02:00
|
|
|
|
2020-08-04 17:01:33 +02:00
|
|
|
const ContentWrapper = styled(Content)`
|
2020-08-04 21:57:24 +02:00
|
|
|
table {
|
|
|
|
table-layout: fixed;
|
|
|
|
/* white-space: nowrap; */
|
|
|
|
}
|
|
|
|
|
|
|
|
td ,thead button {
|
2020-08-04 17:01:33 +02:00
|
|
|
font-size: ${remSize(10)};
|
|
|
|
padding-left: 0;
|
|
|
|
text-align: left;
|
|
|
|
};
|
|
|
|
|
|
|
|
thead th { padding-left: 0; }
|
|
|
|
|
2020-08-04 22:41:41 +02:00
|
|
|
thead th:not(:first-child), tbody td {
|
2020-08-04 22:38:51 +02:00
|
|
|
width: ${remSize(54)};
|
|
|
|
}
|
|
|
|
|
|
|
|
tbody th { font-weight: bold; };
|
2020-08-04 21:57:24 +02:00
|
|
|
|
2020-08-04 22:41:41 +02:00
|
|
|
tbody th {
|
2020-08-04 17:01:33 +02:00
|
|
|
font-size: ${remSize(12)};
|
|
|
|
width: 100%;
|
2020-08-04 21:57:24 +02:00
|
|
|
padding-right: ${remSize(12)}
|
2020-08-04 17:01:33 +02:00
|
|
|
};
|
|
|
|
|
2020-08-04 22:41:41 +02:00
|
|
|
tbody td {
|
2020-08-04 21:57:24 +02:00
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
2020-08-04 17:01:33 +02:00
|
|
|
.sketch-list__sort-button { padding: 0 }
|
2020-08-04 22:41:41 +02:00
|
|
|
tbody {
|
2020-08-04 17:01:33 +02:00
|
|
|
height: ${remSize(48)};
|
|
|
|
}
|
|
|
|
|
|
|
|
.sketches-table-container { padding-bottom: ${remSize(160)} }
|
|
|
|
`;
|
|
|
|
|
2020-07-31 14:04:48 +02:00
|
|
|
const FooterTab = styled(Link)`
|
2020-07-28 16:33:38 +02:00
|
|
|
background: ${props => prop(props.selected ? 'backgroundColor' : 'MobilePanel.default.foreground')};
|
2020-07-24 23:43:07 +02:00
|
|
|
color: ${props => prop(`MobilePanel.default.${props.selected ? 'foreground' : 'background'}`)};
|
2020-08-04 16:03:00 +02:00
|
|
|
padding: ${remSize(8)} ${remSize(16)};
|
2020-07-24 23:43:07 +02:00
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
`;
|
|
|
|
|
2020-07-28 22:46:22 +02:00
|
|
|
const Subheader = styled.div`
|
2020-07-31 15:21:26 +02:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
* { border-radius: 0px; }
|
2020-07-28 22:46:22 +02:00
|
|
|
|
|
|
|
.searchbar {
|
|
|
|
display: flex;
|
2020-07-31 15:21:26 +02:00
|
|
|
width: 100%;
|
2020-07-28 22:46:22 +02:00
|
|
|
}
|
2020-07-28 23:10:20 +02:00
|
|
|
.searchbar__input { width: 100%; }
|
2020-07-28 22:46:22 +02:00
|
|
|
`;
|
|
|
|
|
2020-07-31 15:21:26 +02:00
|
|
|
const SubheaderButton = styled(Button)`
|
|
|
|
border-radius: 0px !important;
|
|
|
|
`;
|
|
|
|
|
2020-07-28 22:46:22 +02:00
|
|
|
|
|
|
|
const FooterTabSwitcher = styled.div`
|
2020-07-24 23:43:07 +02:00
|
|
|
display: flex;
|
|
|
|
|
2020-07-28 16:33:38 +02:00
|
|
|
h3 { text-align: center; width: 100%; }
|
2020-07-24 23:43:07 +02:00
|
|
|
`;
|
|
|
|
|
2020-07-28 16:33:38 +02:00
|
|
|
const Panels = {
|
2020-07-31 14:04:48 +02:00
|
|
|
sketches: SketchList,
|
|
|
|
collections: CollectionList,
|
|
|
|
assets: AssetList
|
2020-07-28 16:33:38 +02:00
|
|
|
};
|
2020-07-24 23:43:07 +02:00
|
|
|
|
2020-07-31 15:21:26 +02:00
|
|
|
const CreatePathname = {
|
|
|
|
sketches: '/mobile',
|
|
|
|
collections: '/mobile/:username/collections/create',
|
|
|
|
};
|
|
|
|
|
2020-07-30 20:40:43 +02:00
|
|
|
|
2020-07-31 14:04:48 +02:00
|
|
|
const getPanel = (pathname) => {
|
|
|
|
const pathparts = pathname ? pathname.split('/') : [];
|
|
|
|
const matches = Object.keys(Panels).map(part => part.toLowerCase()).filter(part => pathparts.includes(part));
|
|
|
|
return matches && matches.length > 0 && matches[0];
|
|
|
|
};
|
|
|
|
|
2020-07-31 15:21:26 +02:00
|
|
|
const getCreatePathname = (panel, username) => (CreatePathname[panel] || '#').replace(':username', username);
|
2020-07-30 20:40:43 +02:00
|
|
|
|
2020-07-31 15:21:26 +02:00
|
|
|
const isOwner = (user, params) => user && params && user.username === params.username;
|
|
|
|
|
2020-08-04 15:55:16 +02:00
|
|
|
const renderPanel = (name, props) => (Component => (Component && <Component {...props} mobile />))(Panels[name]);
|
2020-07-28 22:13:55 +02:00
|
|
|
|
2020-07-31 15:21:26 +02:00
|
|
|
const MobileDashboard = ({ params, location }) => {
|
|
|
|
const user = useSelector(state => state.user);
|
2020-07-30 20:40:43 +02:00
|
|
|
const { username } = params;
|
2020-07-31 14:04:48 +02:00
|
|
|
const { pathname } = location;
|
|
|
|
|
2020-07-31 15:21:26 +02:00
|
|
|
const Tabs = Object.keys(Panels);
|
2020-07-28 22:46:22 +02:00
|
|
|
const isExamples = username === EXAMPLE_USERNAME;
|
2020-07-31 14:04:48 +02:00
|
|
|
const panel = getPanel(pathname);
|
|
|
|
|
2020-07-24 23:43:07 +02:00
|
|
|
return (
|
2020-07-31 14:04:48 +02:00
|
|
|
<Screen fullscreen key={pathname}>
|
2020-07-28 22:13:55 +02:00
|
|
|
<Header slim inverted title={isExamples ? 'Examples' : 'My Stuff'}>
|
2020-07-24 23:43:07 +02:00
|
|
|
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to ide view" />
|
|
|
|
</Header>
|
|
|
|
|
2020-07-28 16:33:38 +02:00
|
|
|
|
2020-08-04 17:01:33 +02:00
|
|
|
<ContentWrapper slimheader>
|
2020-07-28 22:46:22 +02:00
|
|
|
<Subheader>
|
2020-08-04 22:41:41 +02:00
|
|
|
{isOwner(user, params) && (panel !== Tabs[2]) && <SubheaderButton to={getCreatePathname(panel, username)}>new</SubheaderButton>}
|
2020-07-31 14:09:35 +02:00
|
|
|
{panel === Tabs[0] && <SketchSearchbar />}
|
|
|
|
{panel === Tabs[1] && <CollectionSearchbar />}
|
2020-07-28 22:46:22 +02:00
|
|
|
</Subheader>
|
2020-07-31 14:04:48 +02:00
|
|
|
{renderPanel(panel, { username, key: pathname })}
|
2020-08-04 17:01:33 +02:00
|
|
|
</ContentWrapper>
|
2020-07-24 23:43:07 +02:00
|
|
|
<Footer>
|
2020-07-28 22:13:55 +02:00
|
|
|
{!isExamples &&
|
2020-07-28 22:46:22 +02:00
|
|
|
<FooterTabSwitcher>
|
2020-07-28 22:13:55 +02:00
|
|
|
{Tabs.map(tab => (
|
|
|
|
<FooterTab
|
|
|
|
key={`tab-${tab}`}
|
2020-07-31 14:04:48 +02:00
|
|
|
selected={tab === panel}
|
|
|
|
to={pathname.replace(panel, tab)}
|
2020-07-28 22:13:55 +02:00
|
|
|
>
|
2020-07-31 14:04:48 +02:00
|
|
|
<h3>{(isExamples && tab === 'Sketches') ? 'Examples' : tab}</h3>
|
2020-07-28 22:13:55 +02:00
|
|
|
</FooterTab>))
|
|
|
|
}
|
2020-07-28 22:46:22 +02:00
|
|
|
</FooterTabSwitcher>
|
2020-07-28 22:13:55 +02:00
|
|
|
}
|
2020-07-24 23:43:07 +02:00
|
|
|
</Footer>
|
|
|
|
</Screen>);
|
|
|
|
};
|
2020-07-24 23:11:10 +02:00
|
|
|
|
2020-07-31 15:21:26 +02:00
|
|
|
|
2020-07-30 20:40:43 +02:00
|
|
|
MobileDashboard.propTypes = {
|
2020-07-31 14:04:48 +02:00
|
|
|
location: PropTypes.shape({
|
|
|
|
pathname: PropTypes.string.isRequired
|
|
|
|
}).isRequired,
|
2020-07-30 20:40:43 +02:00
|
|
|
params: PropTypes.shape({
|
|
|
|
username: PropTypes.string.isRequired
|
|
|
|
})
|
|
|
|
};
|
|
|
|
MobileDashboard.defaultProps = { params: {} };
|
2020-07-28 22:13:55 +02:00
|
|
|
|
|
|
|
|
2020-07-30 20:40:43 +02:00
|
|
|
export default withRouter(MobileDashboard);
|