🚧 make <Sidebar /> component

This commit is contained in:
ghalestrilo 2020-08-06 15:59:22 -03:00
parent 2ed4664fd3
commit 8b9dd90ae3
4 changed files with 68 additions and 8 deletions

View file

@ -25,7 +25,7 @@ const DropdownWrapper = styled.ul`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: auto; height: auto;
z-index: 9999; z-index: 2;
border-radius: ${remSize(6)}; border-radius: ${remSize(6)};
& li:first-child { border-radius: ${remSize(5)} ${remSize(5)} 0 0; } & li:first-child { border-radius: ${remSize(5)} ${remSize(5)} 0 0; }

View file

@ -0,0 +1,43 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import styled from 'styled-components';
import { remSize, prop, common } from '../theme';
import Header from './mobile/Header';
import IconButton from './mobile/IconButton';
import { ExitIcon } from '../common/icons';
const SidebarWrapper = styled.div`
height: 100%;
width: ${remSize(180)};
position: absolute;
z-index: 2;
left: 0;
background: white;
box-shadow: 0 6px 6px 0 rgba(0,0,0,0.10);
`;
const Sidebar = ({ title, onPressClose }) => (
<SidebarWrapper>
{title &&
<Header slim title={title}>
<IconButton onPress={onPressClose} icon={ExitIcon} aria-label="Return to ide view" />
</Header>}
</SidebarWrapper>
);
Sidebar.propTypes = {
title: PropTypes.string,
onPressClose: PropTypes.func.isRequired,
};
Sidebar.defaultProps = {
title: null,
// onPressClose: PropTypes.func.isRequired,
};
export default Sidebar;

View file

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import { useModalBehavior } from '../utils/custom-hooks'; import { useModalBehavior } from '../utils/custom-hooks';
export default (component) => { export default (component) => {
const [visible, trigger, setRef] = useModalBehavior(); const [visible, trigger, setRef] = useModalBehavior();

View file

@ -34,6 +34,7 @@ import ActionStrip from '../../../components/mobile/ActionStrip';
import useAsModal from '../../../components/useAsModal'; import useAsModal from '../../../components/useAsModal';
import { PreferencesIcon } from '../../../common/icons'; import { PreferencesIcon } from '../../../common/icons';
import Dropdown from '../../../components/Dropdown'; import Dropdown from '../../../components/Dropdown';
import Sidebar from '../../../components/Sidebar';
const isUserOwner = ({ project, user }) => const isUserOwner = ({ project, user }) =>
project.owner && project.owner.id === user.id; project.owner && project.owner.id === user.id;
@ -67,18 +68,13 @@ const MobileIDEView = (props) => {
selectedFile, updateFileContent, files, user, params, selectedFile, updateFileContent, files, user, params,
closeEditorOptions, showEditorOptions, closeEditorOptions, showEditorOptions,
startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console, startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console,
showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState, setUnsavedChanges
} = props; } = props;
const [tmController, setTmController] = useState(null); // eslint-disable-line const [tmController, setTmController] = useState(null); // eslint-disable-line
const { username } = user; const { username } = user;
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown
items={getNatOptions(username)}
align="right"
/>);
// Force state reset // Force state reset
useEffect(clearPersistedState, []); useEffect(clearPersistedState, []);
useEffect(stopSketch, []); useEffect(stopSketch, []);
@ -95,16 +91,34 @@ const MobileIDEView = (props) => {
setCurrentProjectID(params.project_id); setCurrentProjectID(params.project_id);
}, [params, project, username]); }, [params, project, username]);
const [toggleNavDropdown, NavDropDown] = useAsModal(<Dropdown
items={getNatOptions(username)}
align="right"
/>);
const [toggleExplorer, Explorer] = useAsModal(<Sidebar
title="hahaha"
onPressClose={() => {}}
/>);
// toggle sidebar starting opened
useEffect(toggleExplorer, []);
return ( return (
<Screen fullscreen> <Screen fullscreen>
<Explorer />
<Header <Header
title={project.name} title={project.name}
subtitle={selectedFile.name} subtitle={selectedFile.name}
> >
<NavItem> <NavItem>
<IconButton <IconButton
onClick={triggerNavDropdown} onClick={toggleExplorer}
icon={MoreIcon}
aria-label="Options"
/>
<IconButton
onClick={toggleNavDropdown}
icon={MoreIcon} icon={MoreIcon}
aria-label="Options" aria-label="Options"
/> />
@ -147,6 +161,7 @@ const MobileIDEView = (props) => {
hideRuntimeErrorWarning={hideRuntimeErrorWarning} hideRuntimeErrorWarning={hideRuntimeErrorWarning}
runtimeErrorWarningVisible={ide.runtimeErrorWarningVisible} runtimeErrorWarningVisible={ide.runtimeErrorWarningVisible}
provideController={setTmController} provideController={setTmController}
setUnsavedChanges={setUnsavedChanges}
/> />
</IDEWrapper> </IDEWrapper>
@ -267,6 +282,7 @@ MobileIDEView.propTypes = {
username: PropTypes.string, username: PropTypes.string,
}).isRequired, }).isRequired,
setUnsavedChanges: PropTypes.func.isRequired,
getProject: PropTypes.func.isRequired, getProject: PropTypes.func.isRequired,
clearPersistedState: PropTypes.func.isRequired, clearPersistedState: PropTypes.func.isRequired,
params: PropTypes.shape({ params: PropTypes.shape({