From 8b9dd90ae38fcd029d83b7ed3d8cbd0bc216f235 Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Thu, 6 Aug 2020 15:59:22 -0300 Subject: [PATCH 01/13] :construction: make component --- client/components/Dropdown.jsx | 2 +- client/components/Sidebar.jsx | 43 ++++++++++++++++++++++ client/components/useAsModal.jsx | 1 + client/modules/IDE/pages/MobileIDEView.jsx | 30 +++++++++++---- 4 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 client/components/Sidebar.jsx diff --git a/client/components/Dropdown.jsx b/client/components/Dropdown.jsx index bd2169b8..48bed0cb 100644 --- a/client/components/Dropdown.jsx +++ b/client/components/Dropdown.jsx @@ -25,7 +25,7 @@ const DropdownWrapper = styled.ul` display: flex; flex-direction: column; height: auto; - z-index: 9999; + z-index: 2; border-radius: ${remSize(6)}; & li:first-child { border-radius: ${remSize(5)} ${remSize(5)} 0 0; } diff --git a/client/components/Sidebar.jsx b/client/components/Sidebar.jsx new file mode 100644 index 00000000..93bba04d --- /dev/null +++ b/client/components/Sidebar.jsx @@ -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 }) => ( + + {title && +
+ +
} +
+); + +Sidebar.propTypes = { + title: PropTypes.string, + onPressClose: PropTypes.func.isRequired, +}; + +Sidebar.defaultProps = { + title: null, + // onPressClose: PropTypes.func.isRequired, +}; + + +export default Sidebar; diff --git a/client/components/useAsModal.jsx b/client/components/useAsModal.jsx index 1afa0d30..5dbeb82a 100644 --- a/client/components/useAsModal.jsx +++ b/client/components/useAsModal.jsx @@ -1,6 +1,7 @@ import React from 'react'; import { useModalBehavior } from '../utils/custom-hooks'; + export default (component) => { const [visible, trigger, setRef] = useModalBehavior(); diff --git a/client/modules/IDE/pages/MobileIDEView.jsx b/client/modules/IDE/pages/MobileIDEView.jsx index c33c6cda..3d48f7f9 100644 --- a/client/modules/IDE/pages/MobileIDEView.jsx +++ b/client/modules/IDE/pages/MobileIDEView.jsx @@ -34,6 +34,7 @@ import ActionStrip from '../../../components/mobile/ActionStrip'; import useAsModal from '../../../components/useAsModal'; import { PreferencesIcon } from '../../../common/icons'; import Dropdown from '../../../components/Dropdown'; +import Sidebar from '../../../components/Sidebar'; const isUserOwner = ({ project, user }) => project.owner && project.owner.id === user.id; @@ -67,18 +68,13 @@ const MobileIDEView = (props) => { selectedFile, updateFileContent, files, user, params, closeEditorOptions, showEditorOptions, startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console, - showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState + showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState, setUnsavedChanges } = props; const [tmController, setTmController] = useState(null); // eslint-disable-line const { username } = user; - const [triggerNavDropdown, NavDropDown] = useAsModal(); - // Force state reset useEffect(clearPersistedState, []); useEffect(stopSketch, []); @@ -95,16 +91,34 @@ const MobileIDEView = (props) => { setCurrentProjectID(params.project_id); }, [params, project, username]); + const [toggleNavDropdown, NavDropDown] = useAsModal(); + + const [toggleExplorer, Explorer] = useAsModal( {}} + />); + + // toggle sidebar starting opened + useEffect(toggleExplorer, []); return ( +
+ @@ -147,6 +161,7 @@ const MobileIDEView = (props) => { hideRuntimeErrorWarning={hideRuntimeErrorWarning} runtimeErrorWarningVisible={ide.runtimeErrorWarningVisible} provideController={setTmController} + setUnsavedChanges={setUnsavedChanges} /> @@ -267,6 +282,7 @@ MobileIDEView.propTypes = { username: PropTypes.string, }).isRequired, + setUnsavedChanges: PropTypes.func.isRequired, getProject: PropTypes.func.isRequired, clearPersistedState: PropTypes.func.isRequired, params: PropTypes.shape({ From 1680c0cd52e177516dd6d6acc0dd76aba2be7afe Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Thu, 6 Aug 2020 16:05:28 -0300 Subject: [PATCH 02/13] :construction: add background overlay to modals --- client/components/useAsModal.jsx | 21 +++++++++++++++++---- client/modules/IDE/pages/MobileIDEView.jsx | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/client/components/useAsModal.jsx b/client/components/useAsModal.jsx index 5dbeb82a..4e124435 100644 --- a/client/components/useAsModal.jsx +++ b/client/components/useAsModal.jsx @@ -1,11 +1,24 @@ import React from 'react'; +import styled from 'styled-components'; import { useModalBehavior } from '../utils/custom-hooks'; +const BackgroundOverlay = styled.div` + position: absolute; + z-index: 2; + width: 100% !important; + height: 100% !important; + + background: black; + opacity: 0.3; +`; -export default (component) => { - const [visible, trigger, setRef] = useModalBehavior(); +export default (component, hasOverlay = false) => { + const [visible, toggle, setRef] = useModalBehavior(); - const wrapper = () =>
{visible && component}
; // eslint-disable-line + const wrapper = () => (
+ {hasOverlay && visible && } +
{visible && component}
+
); // eslint-disable-line - return [trigger, wrapper]; + return [toggle, wrapper]; }; diff --git a/client/modules/IDE/pages/MobileIDEView.jsx b/client/modules/IDE/pages/MobileIDEView.jsx index 3d48f7f9..a008c079 100644 --- a/client/modules/IDE/pages/MobileIDEView.jsx +++ b/client/modules/IDE/pages/MobileIDEView.jsx @@ -99,7 +99,7 @@ const MobileIDEView = (props) => { const [toggleExplorer, Explorer] = useAsModal( {}} - />); + />, true); // toggle sidebar starting opened useEffect(toggleExplorer, []); From 6d121491aaa0f434e99e1b44487c73195d30beed Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Thu, 6 Aug 2020 16:24:47 -0300 Subject: [PATCH 03/13] :construction: improve useAsModal rendering --- client/components/Sidebar.jsx | 2 +- client/components/mobile/Header.jsx | 10 ++++++---- client/components/useAsModal.jsx | 13 ++++++++----- client/modules/IDE/pages/MobileIDEView.jsx | 3 +-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/client/components/Sidebar.jsx b/client/components/Sidebar.jsx index 93bba04d..962cff36 100644 --- a/client/components/Sidebar.jsx +++ b/client/components/Sidebar.jsx @@ -23,7 +23,7 @@ const SidebarWrapper = styled.div` const Sidebar = ({ title, onPressClose }) => ( {title && -
+
} diff --git a/client/components/mobile/Header.jsx b/client/components/mobile/Header.jsx index cb6702ed..7b3fbae1 100644 --- a/client/components/mobile/Header.jsx +++ b/client/components/mobile/Header.jsx @@ -14,7 +14,7 @@ const textColor = ({ transparent, inverted }) => prop((transparent === false && const HeaderDiv = styled.div` - position: fixed; + ${props => props.fixed && 'position: fixed;'} width: 100%; background: ${props => background(props)}; color: ${textColor}; @@ -57,9 +57,9 @@ const TitleContainer = styled.div` const Header = ({ title, subtitle, leftButton, children, - transparent, inverted, slim + transparent, inverted, slim, fixed }) => ( - + {leftButton} {title &&

{title}

} @@ -79,6 +79,7 @@ Header.propTypes = { transparent: PropTypes.bool, inverted: PropTypes.bool, slim: PropTypes.bool, + fixed: PropTypes.bool, }; Header.defaultProps = { @@ -88,7 +89,8 @@ Header.defaultProps = { children: [], transparent: false, inverted: false, - slim: false + slim: false, + fixed: true }; export default Header; diff --git a/client/components/useAsModal.jsx b/client/components/useAsModal.jsx index 4e124435..52d2fc00 100644 --- a/client/components/useAsModal.jsx +++ b/client/components/useAsModal.jsx @@ -12,13 +12,16 @@ const BackgroundOverlay = styled.div` opacity: 0.3; `; -export default (component, hasOverlay = false) => { +export default (Element, hasOverlay = false) => { const [visible, toggle, setRef] = useModalBehavior(); - const wrapper = () => (
- {hasOverlay && visible && } -
{visible && component}
-
); // eslint-disable-line + // const Comp = styled(() => Element).attrs({ onPressClose: toggle }); + + const wrapper = () => (visible && +
+ {hasOverlay && } +
{Element}
+
); // eslint-disable-line} return [toggle, wrapper]; }; diff --git a/client/modules/IDE/pages/MobileIDEView.jsx b/client/modules/IDE/pages/MobileIDEView.jsx index a008c079..780edba0 100644 --- a/client/modules/IDE/pages/MobileIDEView.jsx +++ b/client/modules/IDE/pages/MobileIDEView.jsx @@ -97,8 +97,7 @@ const MobileIDEView = (props) => { />); const [toggleExplorer, Explorer] = useAsModal( {}} + title="Files" />, true); // toggle sidebar starting opened From d1b4d8d4e38da4fa3e83877f2c8228e4112bcf9f Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Fri, 7 Aug 2020 11:24:25 -0300 Subject: [PATCH 04/13] :broom: remove eslint-disable-line --- client/components/useAsModal.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/useAsModal.jsx b/client/components/useAsModal.jsx index 52d2fc00..a8f4d7d1 100644 --- a/client/components/useAsModal.jsx +++ b/client/components/useAsModal.jsx @@ -21,7 +21,7 @@ export default (Element, hasOverlay = false) => {
{hasOverlay && }
{Element}
-
); // eslint-disable-line} + ); return [toggle, wrapper]; }; From dfedc81f66dda165fdd633e87185e83cdc1516b0 Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Fri, 7 Aug 2020 14:09:17 -0300 Subject: [PATCH 05/13] :sparkles: add files tab --- client/components/mobile/Explorer.jsx | 22 ++++++++++++++++++ client/components/{ => mobile}/Sidebar.jsx | 17 ++++++++------ client/modules/IDE/pages/MobileIDEView.jsx | 26 ++++++++++++++++++---- 3 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 client/components/mobile/Explorer.jsx rename client/components/{ => mobile}/Sidebar.jsx (62%) diff --git a/client/components/mobile/Explorer.jsx b/client/components/mobile/Explorer.jsx new file mode 100644 index 00000000..6d4965b3 --- /dev/null +++ b/client/components/mobile/Explorer.jsx @@ -0,0 +1,22 @@ +import React from 'react'; +import styled from 'styled-components'; +import PropTypes from 'prop-types'; +import Sidebar from './Sidebar'; +import ConnectedFileNode from '../../modules/IDE/components/FileNode'; + + +const Explorer = ({ id, canEdit }) => ( + + + +); + +Explorer.propTypes = { + id: PropTypes.number.isRequired, + canEdit: PropTypes.bool +}; +Explorer.defaultProps = { + canEdit: false +}; + +export default Explorer; diff --git a/client/components/Sidebar.jsx b/client/components/mobile/Sidebar.jsx similarity index 62% rename from client/components/Sidebar.jsx rename to client/components/mobile/Sidebar.jsx index 962cff36..4e2cfda9 100644 --- a/client/components/Sidebar.jsx +++ b/client/components/mobile/Sidebar.jsx @@ -2,10 +2,10 @@ 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'; +import { remSize, prop, common } from '../../theme'; +import Header from './Header'; +import IconButton from './IconButton'; +import { ExitIcon } from '../../common/icons'; const SidebarWrapper = styled.div` @@ -20,23 +20,26 @@ const SidebarWrapper = styled.div` box-shadow: 0 6px 6px 0 rgba(0,0,0,0.10); `; -const Sidebar = ({ title, onPressClose }) => ( +const Sidebar = ({ title, onPressClose, children }) => ( {title &&
} + {children}
); Sidebar.propTypes = { title: PropTypes.string, - onPressClose: PropTypes.func.isRequired, + onPressClose: PropTypes.func, + children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]), }; Sidebar.defaultProps = { title: null, - // onPressClose: PropTypes.func.isRequired, + children: [], + onPressClose: () => {} }; diff --git a/client/modules/IDE/pages/MobileIDEView.jsx b/client/modules/IDE/pages/MobileIDEView.jsx index 780edba0..9bad5903 100644 --- a/client/modules/IDE/pages/MobileIDEView.jsx +++ b/client/modules/IDE/pages/MobileIDEView.jsx @@ -27,6 +27,7 @@ import Header from '../../../components/mobile/Header'; import Screen from '../../../components/mobile/MobileScreen'; import Footer from '../../../components/mobile/Footer'; import IDEWrapper from '../../../components/mobile/IDEWrapper'; +import MobileExplorer from '../../../components/mobile/Explorer'; import Console from '../components/Console'; import { remSize } from '../../../theme'; // import OverlayManager from '../../../components/OverlayManager'; @@ -34,11 +35,28 @@ import ActionStrip from '../../../components/mobile/ActionStrip'; import useAsModal from '../../../components/useAsModal'; import { PreferencesIcon } from '../../../common/icons'; import Dropdown from '../../../components/Dropdown'; -import Sidebar from '../../../components/Sidebar'; +import Sidebar from '../../../components/mobile/Sidebar'; + + +const getRootFile = files => files && files.filter(file => file.name === 'root')[0]; +const getRootFileID = files => (root => root && root.id)(getRootFile(files)); const isUserOwner = ({ project, user }) => project.owner && project.owner.id === user.id; + +// const userCanEditProject = (props) => { +// let canEdit; +// if (!props.owner) { +// canEdit = true; +// } else if (props.user.authenticated && props.owner.id === props.user.id) { +// canEdit = true; +// } else { +// canEdit = false; +// } +// return canEdit; +// }; + const Expander = styled.div` height: ${props => (props.expanded ? remSize(160) : remSize(27))}; `; @@ -75,6 +93,7 @@ const MobileIDEView = (props) => { const { username } = user; + // Force state reset useEffect(clearPersistedState, []); useEffect(stopSketch, []); @@ -91,14 +110,13 @@ const MobileIDEView = (props) => { setCurrentProjectID(params.project_id); }, [params, project, username]); + // Screen Modals const [toggleNavDropdown, NavDropDown] = useAsModal(); - const [toggleExplorer, Explorer] = useAsModal(, true); + const [toggleExplorer, Explorer] = useAsModal(, true); // toggle sidebar starting opened useEffect(toggleExplorer, []); From 34be0e700de8c47c2efe6f6e7df30ad5055dcbff Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Fri, 7 Aug 2020 14:17:26 -0300 Subject: [PATCH 06/13] :sparkles: add visibility padding to the bottom of the editor wrapper --- client/components/mobile/IDEWrapper.jsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/components/mobile/IDEWrapper.jsx b/client/components/mobile/IDEWrapper.jsx index 0982cf81..5e66ee01 100644 --- a/client/components/mobile/IDEWrapper.jsx +++ b/client/components/mobile/IDEWrapper.jsx @@ -2,7 +2,10 @@ import React from 'react'; import styled from 'styled-components'; import { remSize } from '../../theme'; +// Applies padding to top and bottom so editor content is always visible + export default styled.div` z-index: 0; margin-top: ${remSize(16)}; + .CodeMirror-sizer > * { padding-bottom: ${remSize(320)}; }; `; From 81ad78ba79c45331de154310d1d1ae1eec4f7039 Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Fri, 7 Aug 2020 15:03:18 -0300 Subject: [PATCH 07/13] :sparkles: add floating button to open files tab --- client/common/icons.jsx | 8 +++++ client/components/mobile/FloatingNav.jsx | 40 ++++++++++++++++++++++ client/images/circle-folder.svg | 5 +++ client/images/circle-info.svg | 4 +++ client/images/circle-terminal.svg | 6 ++++ client/modules/App/App.jsx | 4 ++- client/modules/IDE/pages/MobileIDEView.jsx | 22 ++++++------ 7 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 client/components/mobile/FloatingNav.jsx create mode 100644 client/images/circle-folder.svg create mode 100644 client/images/circle-info.svg create mode 100644 client/images/circle-terminal.svg diff --git a/client/common/icons.jsx b/client/common/icons.jsx index 215083a6..b03c3c0f 100644 --- a/client/common/icons.jsx +++ b/client/common/icons.jsx @@ -16,6 +16,10 @@ import More from '../images/more.svg'; import Code from '../images/code.svg'; import Terminal from '../images/terminal.svg'; +import CircleTerminal from '../images/circle-terminal.svg'; +import CircleFolder from '../images/circle-folder.svg'; +import CircleInfo from '../images/circle-info.svg'; + // HOC that adds the right web accessibility props // https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html @@ -81,3 +85,7 @@ export const PlayIcon = withLabel(Play); export const MoreIcon = withLabel(More); export const TerminalIcon = withLabel(Terminal); export const CodeIcon = withLabel(Code); + +export const CircleTerminalIcon = withLabel(CircleTerminal); +export const CircleFolderIcon = withLabel(CircleFolder); +export const CircleInfoIcon = withLabel(CircleInfo); diff --git a/client/components/mobile/FloatingNav.jsx b/client/components/mobile/FloatingNav.jsx new file mode 100644 index 00000000..ca8220f7 --- /dev/null +++ b/client/components/mobile/FloatingNav.jsx @@ -0,0 +1,40 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import styled from 'styled-components'; +import { remSize } from '../../theme'; +import Button from '../../common/Button'; +import IconButton from './IconButton'; + +const FloatingContainer = styled.div` + position: absolute; + right: ${remSize(16)}; + top: ${remSize(80)}; + + text-align: right; + z-index: 3; +`; + +const FloatingNav = ({ items }) => ( + + { items.map(({ icon, onPress }) => + ( + + ))} + +); + +FloatingNav.propTypes = { + items: PropTypes.arrayOf(PropTypes.shape({ + icon: PropTypes.element, + onPress: PropTypes.func + })) +}; + +FloatingNav.defaultProps = { + items: [] +}; + +export default FloatingNav; diff --git a/client/images/circle-folder.svg b/client/images/circle-folder.svg new file mode 100644 index 00000000..ab2076b9 --- /dev/null +++ b/client/images/circle-folder.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/client/images/circle-info.svg b/client/images/circle-info.svg new file mode 100644 index 00000000..ed75766b --- /dev/null +++ b/client/images/circle-info.svg @@ -0,0 +1,4 @@ + + + + diff --git a/client/images/circle-terminal.svg b/client/images/circle-terminal.svg new file mode 100644 index 00000000..168efd85 --- /dev/null +++ b/client/images/circle-terminal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/client/modules/App/App.jsx b/client/modules/App/App.jsx index af441a9d..96013836 100644 --- a/client/modules/App/App.jsx +++ b/client/modules/App/App.jsx @@ -34,7 +34,9 @@ class App extends React.Component { render() { return (
- {this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && } +
+ {this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && } +
{this.props.children}
); diff --git a/client/modules/IDE/pages/MobileIDEView.jsx b/client/modules/IDE/pages/MobileIDEView.jsx index 9bad5903..2d6fb526 100644 --- a/client/modules/IDE/pages/MobileIDEView.jsx +++ b/client/modules/IDE/pages/MobileIDEView.jsx @@ -20,7 +20,7 @@ import { getHTMLFile } from '../reducers/files'; // Local Imports import Editor from '../components/Editor'; -import { PlayIcon, MoreIcon } from '../../../common/icons'; +import { PlayIcon, MoreIcon, CircleFolderIcon } from '../../../common/icons'; import IconButton from '../../../components/mobile/IconButton'; import Header from '../../../components/mobile/Header'; @@ -30,12 +30,12 @@ import IDEWrapper from '../../../components/mobile/IDEWrapper'; import MobileExplorer from '../../../components/mobile/Explorer'; import Console from '../components/Console'; import { remSize } from '../../../theme'; -// import OverlayManager from '../../../components/OverlayManager'; + import ActionStrip from '../../../components/mobile/ActionStrip'; import useAsModal from '../../../components/useAsModal'; import { PreferencesIcon } from '../../../common/icons'; import Dropdown from '../../../components/Dropdown'; -import Sidebar from '../../../components/mobile/Sidebar'; +import FloatingNav from '../../../components/mobile/FloatingNav'; const getRootFile = files => files && files.filter(file => file.name === 'root')[0]; @@ -65,7 +65,7 @@ const NavItem = styled.li` position: relative; `; -const getNatOptions = (username = undefined) => +const getNavOptions = (username = undefined) => (username ? [ { icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', }, @@ -112,14 +112,18 @@ const MobileIDEView = (props) => { // Screen Modals const [toggleNavDropdown, NavDropDown] = useAsModal(); + const [toggleExplorer, Explorer] = useAsModal(, true); // toggle sidebar starting opened - useEffect(toggleExplorer, []); + // useEffect(toggleExplorer, []); + + const floatingNavOptions = + [{ icon: CircleFolderIcon, onPress: toggleExplorer }]; return ( @@ -129,11 +133,6 @@ const MobileIDEView = (props) => { subtitle={selectedFile.name} > - { provideController={setTmController} setUnsavedChanges={setUnsavedChanges} /> +