Skip to content

Mobile Sketch Preview Screen #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0d119aa
:construction: emplace settings and play icons
ghalestrilo Jun 16, 2020
bdedc63
:construction: add icons to header
ghalestrilo Jun 16, 2020
0877d39
:construction: split components into files
ghalestrilo Jun 16, 2020
5c80702
:construction: add MobileSketchView screen to /mobile/preview
ghalestrilo Jun 18, 2020
49a9fe7
:construction: make link to /mobile
ghalestrilo Jun 18, 2020
e5bbb53
:construction: create alternate content wrapper for proper top padding
ghalestrilo Jun 18, 2020
0633c3b
:construction: mount <PreviewFrame /> on /mobile/preview
ghalestrilo Jun 18, 2020
e11756d
:construction: correct hook call for getProject
ghalestrilo Jun 19, 2020
8a067a8
:construction: make mobile IDE screen start the sketch
ghalestrilo Jun 19, 2020
123c2b0
🔀 merge from origin/develop
ghalestrilo Jun 19, 2020
d00506a
:construction: mound the <PreviewFrame /> properly on Mobile Preview …
ghalestrilo Jun 19, 2020
a11bc44
:sparkles: render sketch
ghalestrilo Jun 19, 2020
776c3d2
:recycle: refactor call to PreviewFrame#renderSketch
ghalestrilo Jun 19, 2020
eb3bc59
:broom: clean up routes.js
ghalestrilo Jun 19, 2020
0e66756
:bug: correct projectName propType to string
ghalestrilo Jun 19, 2020
597cb9b
:sparkles: strech preview canvas to full-width on demand
ghalestrilo Jun 19, 2020
7604e27
:ok_hand: mark comment on routes.jsx as TODO
ghalestrilo Jun 29, 2020
ec8566f
:ok_hand: remove empty useEffect
ghalestrilo Jun 29, 2020
ebb9525
:ok_hand: move icons to common/icons
ghalestrilo Jun 29, 2020
75bd5a3
:ok_hand: remove eslint-disable
ghalestrilo Jun 29, 2020
1eb1bff
:ok_hand: remove debugger comment
ghalestrilo Jun 29, 2020
c39211d
:ok_hand: remove linter comment
ghalestrilo Jun 29, 2020
78ec304
:ok_hand: remove eslint-disable
ghalestrilo Jun 29, 2020
9ca0995
:ok_hand: create Panel color object in theme
ghalestrilo Jun 29, 2020
7d24c07
:ok_hand: use common/Button component for IconButton
ghalestrilo Jun 29, 2020
8a0b09d
:ok_hand: use common/Button component for IconButton on screens
ghalestrilo Jun 29, 2020
7805acc
:bug: fix margin on header title
ghalestrilo Jun 29, 2020
a1d6abf
:ok_hand: rename Panel to MobilePanel on theme.js
ghalestrilo Jul 1, 2020
3143cc3
:ok_hand: change IconButton structure
ghalestrilo Jul 1, 2020
b4c1b86
:ok_hand: improve IconButton implementation
ghalestrilo Jul 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/common/icons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Plus from '../images/plus-icon.svg';
import Close from '../images/close.svg';
import Exit from '../images/exit.svg';
import DropdownArrow from '../images/down-filled-triangle.svg';
import Preferences from '../images/preferences.svg';
import Play from '../images/triangle-arrow-right.svg';

// HOC that adds the right web accessibility props
// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html
Expand Down Expand Up @@ -70,3 +72,5 @@ export const PlusIcon = withLabel(Plus);
export const CloseIcon = withLabel(Close);
export const ExitIcon = withLabel(Exit);
export const DropdownArrowIcon = withLabel(DropdownArrow);
export const PreferencesIcon = withLabel(Preferences);
export const PlayIcon = withLabel(Play);
2 changes: 1 addition & 1 deletion client/components/mobile/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import { prop, remSize } from '../../theme';

const background = prop('Button.default.background');
const background = prop('Panel.default.background');
const textColor = prop('primaryTextColor');

const Footer = styled.div`
Expand Down
11 changes: 8 additions & 3 deletions client/components/mobile/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import { prop, remSize } from '../../theme';

const background = prop('Button.default.background');
const background = prop('Panel.default.background');
const textColor = prop('primaryTextColor');

const Header = styled.div`
Expand All @@ -11,15 +11,20 @@ const Header = styled.div`
background: ${background};
color: ${textColor};
padding: ${remSize(12)};
padding-left: ${remSize(32)};
padding-right: ${remSize(32)};
padding-left: ${remSize(16)};
padding-right: ${remSize(16)};
z-index: 1;

display: flex;
flex: 1;
flex-direction: row;
justify-content: flex-start;
align-items: center;

// TODO:
svg {
height: 2rem;
}
`;

export default Header;
21 changes: 14 additions & 7 deletions client/components/mobile/IconButton.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { prop, remSize } from '../../theme';
import Button from '../../common/Button';

const textColor = prop('primaryTextColor');

const IconButton = styled.button`
const ButtonWrapper = styled(Button)`
width: 3rem;
> svg {
width: 100%;
height: auto;
fill: ${textColor};
stroke: ${textColor};
height: 100%;
}
`;

const IconButton = props => (<ButtonWrapper
iconBefore={props.children}
kind={Button.kinds.inline}
{...{ ...props, children: null }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to put children: null here? Isn't children null here if you just don't put anything in between <ButtonWrapper></ButtonWrapper>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's null if I don't pass anything, but in this case I wanted to pass children into the iconBefore prop, and not into the body of the component.
I thought of a better solution, so I'll change this soon

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced an icon prop, now it looks a lot cleaner

/>);

IconButton.propTypes = {
children: PropTypes.element.isRequired
};

export default IconButton;
2 changes: 0 additions & 2 deletions client/modules/IDE/components/PreviewFrame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { hijackConsoleErrorsScript, startTag, getAllScriptOffsets }
from '../../../utils/consoleUtils';


// Kept inside class just for linter's
const shouldRenderSketch = (props, prevProps = undefined) => {
const { isPlaying, previewIsRefreshing, fullView } = props;

Expand Down Expand Up @@ -337,7 +336,6 @@ class PreviewFrame extends React.Component {
if (this.props.endSketchRefresh) {
this.props.endSketchRefresh();
}
// debugger; // eslint-disable-line
} else {
doc.srcdoc = '';
srcDoc.set(doc, ' ');
Expand Down
52 changes: 24 additions & 28 deletions client/modules/IDE/pages/IDEViewMobile.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
Expand All @@ -23,59 +22,56 @@ import { getHTMLFile } from '../reducers/files';
import Editor from '../components/Editor';
import { ExitIcon } from '../../../common/icons';

import PreferencesIcon from '../../../images/preferences.svg';
import PlayIcon from '../../../images/triangle-arrow-right.svg';
import { PreferencesIcon, PlayIcon } from '../../../common/icons';

import IconButton from '../../../components/mobile/IconButton';
import Header from '../../../components/mobile/Header';
import Screen from '../../../components/mobile/MobileScreen';
import Footer from '../../../components/mobile/Footer';
import IDEWrapper from '../../../components/mobile/IDEWrapper';

const IconLinkWrapper = styled(Link)`
width: 3rem;
margin-right: 1.25rem;
margin-left: none;
const IconContainer = styled.div`
marginLeft: 2rem;
display: flex;
`;

const TitleContainer = styled.div`

`;

const isUserOwner = ({ project, user }) => (project.owner && project.owner.id === user.id);

const IDEViewMobile = (props) => {
const {
preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage, selectedFile, updateFileContent, files, closeEditorOptions, showEditorOptions, showKeyboardShortcutModal, setUnsavedChanges, startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console, showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch
preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage,
selectedFile, updateFileContent, files,
closeEditorOptions, showEditorOptions, showKeyboardShortcutModal, setUnsavedChanges,
startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console,
showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch
} = props;

const [tmController, setTmController] = useState(null);

const [overlay, setOverlay] = useState(null);
const [tmController, setTmController] = useState(null); // eslint-disable-line
const [overlay, setOverlay] = useState(null); // eslint-disable-line

return (
<Screen>
<Header>
<IconLinkWrapper to="/" aria-label="Return to original editor">
<ExitIcon />
</IconLinkWrapper>
<div>
<IconButton to="/mobile" aria-label="Return to original editor">
<ExitIcon viewBox="0 0 16 16" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using viewbox here to change the size of the icon? I would prefer if you explicitly set the width and height, and maybe this needs to be added to client/common/icons.jsx, which could be done in a separate PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the viewbox prop for now, and find a way to resize the icon in a future PR, to minimize conflicts with the other branch

</IconButton>
<div style={{ marginLeft: '1rem' }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible i would prefer to not have inline styles!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next PR fixes this by improving the structure of the <Header /> component

<h2>{project.name}</h2>
<h3>{selectedFile.name}</h3>
</div>

<div style={{ marginLeft: '2rem' }}>
<IconContainer>
<IconButton onClick={() => setOverlay('preferences')}>
<PreferencesIcon focusable="false" aria-hidden="true" />
</IconButton>
<Link
to="/mobile/preview"
onClick={() => {
// alert('starting sketch');
startSketch();
}}
>
<IconButton>
<PlayIcon viewBox="-1 -1 7 7" focusable="false" aria-hidden="true" />
</IconButton>
</Link>
</div>
<IconButton to="/mobile/preview" onClick={() => { startSketch(); }}>
<PlayIcon viewBox="-1 -1 7 7" focusable="false" aria-hidden="true" />
</IconButton>
</IconContainer>
</Header>

<IDEWrapper>
Expand Down
21 changes: 5 additions & 16 deletions client/modules/Mobile/MobileSketchView.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable */
import React, { useEffect } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import styled from 'styled-components';
import Header from '../../components/mobile/Header';
import IconButton from '../../components/mobile/IconButton';
import PreviewFrame from '../IDE/components/PreviewFrame';
import Screen from '../../components/mobile/MobileScreen';
import * as ProjectActions from '../IDE/actions/project';
Expand All @@ -26,12 +26,6 @@ const Content = styled.div`
margin-top: ${remSize(68)};
`;

const IconLinkWrapper = styled(Link)`
width: 2rem;
margin-right: 1.25rem;
margin-left: none;
`;

const MobileSketchView = (props) => {
// TODO: useSelector requires react-redux ^7.1.0
// const htmlFile = useSelector(state => getHTMLFile(state.files));
Expand All @@ -53,18 +47,13 @@ const MobileSketchView = (props) => {

const { preferences, ide } = props;

useEffect(() => {
// console.log(params);
// getProject(params.project_id, params.username);
});

return (
<Screen>
<Header>
<IconLinkWrapper to="/mobile" aria-label="Return to original editor">
<IconButton to="/mobile" aria-label="Return to original editor">
<ExitIcon viewBox="0 0 16 16" />
</IconLinkWrapper>
<div>
</IconButton>
<div style={{ marginLeft: '1rem' }}>
<h2>{projectName}</h2>
<h3><br /></h3>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this mark-up?

<h3><br /></h3>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just heightens the header by an h3 height, to keep the h2 tag aligned with the previous screen - couldn't think of a better way to do this...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have to use CSS to add padding to the h2? And maybe set the previous screens header to a know height?

Using h3 is this way is not semantic especially as screen-readers allow the user to list and navigate via the headings in the page, which will be empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'm fixing this on the next PR, and improving the <Header /> component as well

</div>
Expand Down
2 changes: 1 addition & 1 deletion client/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const checkAuth = (store) => {
store.dispatch(getUser());
};

// This short-circuit seems unnecessary - using the mobile <Switch /> navigator (future) should prevent this from being called
// TODO: This short-circuit seems unnecessary - using the mobile <Switch /> navigator (future) should prevent this from being called
const onRouteChange = (store) => {
const path = window.location.pathname;
if (path.includes('/mobile')) return;
Expand Down
21 changes: 21 additions & 0 deletions client/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export default {
Icon: {
default: grays.middleGray,
hover: grays.darker
},
Panel: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are same colours as the buttons, so we'll have a problem if someone later puts a Button on top of a Panel as they'll be the same.

Shall we take the colours from the console header component? Cassie made accessibility colour changes a a while back to ensure the contrast worked across all the themes.

So:

Panel.default.foreground should be the value of console-header-color
Panel.default.background should be the value of console-header-background-color
Panel.default.border should be the value of ide-border-color

The colours are here.

I know it's a bit of a pain to do this, but it'll really help with the move to styled-components and away from SCSS and helping to make the design more consistent.

Copy link
Collaborator Author

@ghalestrilo ghalestrilo Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but these are the colors that Panels use on the mobile UI (on Headers and Footers at least), so I'm not sure what to do. I wonder if they even mean the same thing on both UIs.

I think I'll create a Panel: { mobile: {} } attribute and keep these colors there, so the default Panel colors can be set to those of the default UI. Do you think that makes sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, it would be great to have the same set of colours work for mobile and the legacy UI. My feeling is branching the theme into Panel.mobile and Panel.notMobile creates more code for us to maintain.

Your right that maybe this isn't a reusable panel colour, so if it's not possible to find common colours, then my preference is that we name the variable something other than Panel.

@catarak, what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I investigated this a bit, and It's an important decision that goes beyond the scope of the PR, so I'll create an issue and we can discuss it there!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good idea.

So shall we call this MobilePanel or something for now and we can get this merged in?

Copy link
Member

@catarak catarak Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @andrewn, that it would be helpful if possible to not have mobile specific colors.

@ghalestrilo and I talked this over and thought it would make sense to open a new issue/PR with respect to the panel and button color contrasts, see #1484.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'll update this :)

default: {
foreground: colors.black,
background: grays.light,
border: grays.middleLight,
},
}
},
[Theme.dark]: {
Expand Down Expand Up @@ -120,6 +127,13 @@ export default {
Icon: {
default: grays.middleLight,
hover: grays.lightest
},
Panel: {
default: {
foreground: grays.light,
background: grays.dark,
border: grays.middleDark,
},
}
},
[Theme.contrast]: {
Expand Down Expand Up @@ -152,6 +166,13 @@ export default {
Icon: {
default: grays.mediumLight,
hover: colors.yellow
},
Panel: {
default: {
foreground: grays.light,
background: grays.dark,
border: grays.middleDark,
},
}
},
};