Skip to content

Add Login/Logout functionality to mobile layout #1543

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 11 commits into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 21 additions & 10 deletions client/components/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ const DropdownWrapper = styled.ul`
background-color: ${prop('Button.hover.background')};
color: ${prop('Button.hover.foreground')};

& button, & a {
color: ${prop('Button.hover.foreground')};
}
* { color: ${prop('Button.hover.foreground')}; }
}

li {
Expand All @@ -48,12 +46,21 @@ const DropdownWrapper = styled.ul`
align-items: center;

& button,
& button span,
& a {
padding: ${remSize(8)} ${remSize(16)};
}

* {
text-align: left;
justify-content: left;

color: ${prop('primaryTextColor')};
width: 100%;
text-align: left;
padding: ${remSize(8)} ${remSize(16)};
justify-content: flex-start;
}

& button span { padding: 0px }
}
`;

Expand All @@ -63,18 +70,22 @@ const DropdownWrapper = styled.ul`
const Dropdown = ({ items, align }) => (
<DropdownWrapper align={align} >
{/* className="nav__items-left" */}
{items && items.map(({ title, icon, href }) => (
{items && items.map(({
title, icon, href, action
}) => (
<li key={`nav-${title && title.toLowerCase()}`}>
<Link to={href}>
{/* {MaybeIcon(icon, `Navigate to ${title}`)} */}
{title}
</Link>
{/* {MaybeIcon(icon, `Navigate to ${title}`)} */}
{href
? <IconButton to={href}>{title}</IconButton>
: <IconButton onClick={() => action()}>{title}</IconButton>}

</li>
))
}
</DropdownWrapper>
);


Dropdown.propTypes = {
align: PropTypes.oneOf(['left', 'right']),
items: PropTypes.arrayOf(PropTypes.shape({
Expand Down
8 changes: 6 additions & 2 deletions client/components/mobile/IconButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ const IconButton = (props) => {
const Icon = icon;

return (<ButtonWrapper
iconBefore={<Icon />}
iconBefore={icon && <Icon />}
kind={Button.kinds.inline}
focusable="false"
{...otherProps}
/>);
};

IconButton.propTypes = {
icon: PropTypes.func.isRequired
icon: PropTypes.func
};

IconButton.defaultProps = {
icon: null
};

export default IconButton;
12 changes: 8 additions & 4 deletions client/modules/IDE/pages/MobileIDEView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getHTMLFile } from '../reducers/files';

// Local Imports
import Editor from '../components/Editor';
import { PlayIcon, MoreIcon, CircleFolderIcon } from '../../../common/icons';
import { PlayIcon, MoreIcon } from '../../../common/icons';

import IconButton from '../../../components/mobile/IconButton';
import Header from '../../../components/mobile/Header';
Expand Down Expand Up @@ -63,26 +63,28 @@ const NavItem = styled.li`
position: relative;
`;

const getNavOptions = (username = undefined) =>
const getNavOptions = (username = undefined, logoutUser = () => {}) =>
(username
? [
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
{ icon: PreferencesIcon, title: 'My Stuff', href: `/mobile/${username}/sketches` },
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', },
{ icon: PreferencesIcon, title: 'Logout', action: logoutUser, },
]
: [
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', },
{ icon: PreferencesIcon, title: 'Login', href: '/login', },
]
);

const MobileIDEView = (props) => {
const {
preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage,
selectedFile, updateFileContent, files, user, params,
closeEditorOptions, showEditorOptions,
closeEditorOptions, showEditorOptions, logoutUser,
startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console,
showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState, setUnsavedChanges
} = props;
Expand Down Expand Up @@ -110,7 +112,7 @@ const MobileIDEView = (props) => {

// Screen Modals
const [toggleNavDropdown, NavDropDown] = useAsModal(<Dropdown
items={getNavOptions(username)}
items={getNavOptions(username, logoutUser)}
align="right"
/>);

Expand Down Expand Up @@ -294,6 +296,8 @@ MobileIDEView.propTypes = {
username: PropTypes.string,
}).isRequired,

logoutUser: PropTypes.func.isRequired,

setUnsavedChanges: PropTypes.func.isRequired,
getProject: PropTypes.func.isRequired,
clearPersistedState: PropTypes.func.isRequired,
Expand Down
64 changes: 64 additions & 0 deletions client/modules/User/components/ResponsiveForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { remSize } from '../../../theme';


const ResponsiveFormWrapper = styled.div`
.form-container__content {
width: unset !important;
padding-top: ${remSize(16)};
padding-bottom: ${remSize(64)};
}

.form__input {
min-width: unset;
padding: 0px ${remSize(12)};
height: ${remSize(28)};
}
.form-container__title { margin-bottom: ${remSize(14)}}
p.form__field { margin-top: 0px !important; }
label.form__label { margin-top: ${remSize(8)} !important; }

.form-error { width: 100% }

.nav__items-right:last-child { display: none }

.form-container {
height: 100%
}

.nav__dropdown {
right: 0 !important;
left: unset !important;
}

.form-container__stack {
svg {
width: ${remSize(12)};
height: ${remSize(12)}
}
a { padding: 0px }
}
`;

const ResponsiveForm = props =>
(props.mobile === true
? (
<ResponsiveFormWrapper>
{props.children}
</ResponsiveFormWrapper>

)
: props.children);

ResponsiveForm.propTypes = {
mobile: PropTypes.bool,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.array]),
};
ResponsiveForm.defaultProps = {
mobile: false,
children: []
};

export default ResponsiveForm;
59 changes: 33 additions & 26 deletions client/modules/User/pages/LoginView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import LoginForm from '../components/LoginForm';
import { validateLogin } from '../../../utils/reduxFormUtils';
import SocialAuthButton from '../components/SocialAuthButton';
import Nav from '../../../components/Nav';
import ResponsiveForm from '../components/ResponsiveForm';

class LoginView extends React.Component {
constructor(props) {
Expand All @@ -27,36 +28,40 @@ class LoginView extends React.Component {
}

render() {
const isMobile = () => (window.innerWidth < 770);
if (this.props.user.authenticated) {
this.gotoHomePage();
return null;
}
// TODO: mobile currently forced to true
return (
<div className="login">
<Nav layout="dashboard" />
<main className="form-container">
<Helmet>
<title>{this.props.t('LoginView.Title')}</title>
</Helmet>
<div className="form-container__content">
<h2 className="form-container__title">{this.props.t('LoginView.Login')}</h2>
<LoginForm {...this.props} />
<h2 className="form-container__divider">{this.props.t('LoginView.LoginOr')}</h2>
<div className="form-container__stack">
<SocialAuthButton service={SocialAuthButton.services.github} />
<SocialAuthButton service={SocialAuthButton.services.google} />
<ResponsiveForm mobile={isMobile() || this.props.mobile}>
<div className="login">
<Nav layout="dashboard" />
<main className="form-container">
<Helmet>
<title>{this.props.t('LoginView.Title')}</title>
</Helmet>
<div className="form-container__content">
<h2 className="form-container__title">{this.props.t('LoginView.Login')}</h2>
<LoginForm {...this.props} />
<h2 className="form-container__divider">{this.props.t('LoginView.LoginOr')}</h2>
<div className="form-container__stack">
<SocialAuthButton service={SocialAuthButton.services.github} />
<SocialAuthButton service={SocialAuthButton.services.google} />
</div>
<p className="form__navigation-options">
{this.props.t('LoginView.DontHaveAccount')}
<Link className="form__signup-button" to="/signup">{this.props.t('LoginView.SignUp')}</Link>
</p>
<p className="form__navigation-options">
{this.props.t('LoginView.ForgotPassword')}
<Link className="form__reset-password-button" to="/reset-password"> {this.props.t('LoginView.ResetPassword')}</Link>
</p>
</div>
<p className="form__navigation-options">
{this.props.t('LoginView.DontHaveAccount')}
<Link className="form__signup-button" to="/signup">{this.props.t('LoginView.SignUp')}</Link>
</p>
<p className="form__navigation-options">
{this.props.t('LoginView.ForgotPassword')}
<Link className="form__reset-password-button" to="/reset-password"> {this.props.t('LoginView.ResetPassword')}</Link>
</p>
</div>
</main>
</div>
</main>
</div>
</ResponsiveForm>
);
}
}
Expand All @@ -79,13 +84,15 @@ LoginView.propTypes = {
user: PropTypes.shape({
authenticated: PropTypes.bool
}),
t: PropTypes.func.isRequired
t: PropTypes.func.isRequired,
mobile: PropTypes.bool
};

LoginView.defaultProps = {
user: {
authenticated: false
}
},
mobile: false
};

export default withTranslation()(reduxForm({
Expand Down
51 changes: 29 additions & 22 deletions client/modules/User/pages/SignupView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import apiClient from '../../../utils/apiClient';
import { validateSignup } from '../../../utils/reduxFormUtils';
import SocialAuthButton from '../components/SocialAuthButton';
import Nav from '../../../components/Nav';
import ResponsiveForm from '../components/ResponsiveForm';

const isMobile = () => (window.innerWidth < 770);

class SignupView extends React.Component {
gotoHomePage = () => {
Expand All @@ -23,27 +26,29 @@ class SignupView extends React.Component {
return null;
}
return (
<div className="signup">
<Nav layout="dashboard" />
<main className="form-container">
<Helmet>
<title>{this.props.t('SignupView.Title')}</title>
</Helmet>
<div className="form-container__content">
<h2 className="form-container__title">{this.props.t('SignupView.Description')}</h2>
<SignupForm {...this.props} />
<h2 className="form-container__divider">{this.props.t('SignupView.Or')}</h2>
<div className="form-container__stack">
<SocialAuthButton service={SocialAuthButton.services.github} />
<SocialAuthButton service={SocialAuthButton.services.google} />
<ResponsiveForm mobile={isMobile() || this.props.mobile}>
<div className="signup">
<Nav layout="dashboard" />
<main className="form-container">
<Helmet>
<title>{this.props.t('SignupView.Title')}</title>
</Helmet>
<div className="form-container__content">
<h2 className="form-container__title">{this.props.t('SignupView.Description')}</h2>
<SignupForm {...this.props} />
<h2 className="form-container__divider">{this.props.t('SignupView.Or')}</h2>
<div className="form-container__stack">
<SocialAuthButton service={SocialAuthButton.services.github} />
<SocialAuthButton service={SocialAuthButton.services.google} />
</div>
<p className="form__navigation-options">
{this.props.t('SignupView.AlreadyHave')}
<Link className="form__login-button" to="/login">{this.props.t('SignupView.Login')}</Link>
</p>
</div>
<p className="form__navigation-options">
{this.props.t('SignupView.AlreadyHave')}
<Link className="form__login-button" to="/login">{this.props.t('SignupView.Login')}</Link>
</p>
</div>
</main>
</div>
</main>
</div>
</ResponsiveForm>
);
}
}
Expand Down Expand Up @@ -110,13 +115,15 @@ SignupView.propTypes = {
user: PropTypes.shape({
authenticated: PropTypes.bool
}),
t: PropTypes.func.isRequired
t: PropTypes.func.isRequired,
mobile: PropTypes.bool
};

SignupView.defaultProps = {
user: {
authenticated: false
}
},
mobile: false
};

export default withTranslation()(reduxForm({
Expand Down