make login/logout options on dropdown

This commit is contained in:
ghalestrilo 2020-08-12 10:19:06 -03:00
parent a28a4a5c83
commit 32efc40298
4 changed files with 24 additions and 12 deletions

View file

@ -58,23 +58,27 @@ const DropdownWrapper = styled.ul`
`; `;
// TODO: Add Icon to the left of the items in the menu // TODO: Add Icon to the left of the items in the menu
// const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />; const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />;
const Dropdown = ({ items, align }) => ( const Dropdown = ({ items, align }) => (
<DropdownWrapper align={align} > <DropdownWrapper align={align} >
{/* className="nav__items-left" */} {/* className="nav__items-left" */}
{items && items.map(({ title, icon, href }) => ( {items && items.map(({
title, icon, href, action
}) => (
<li key={`nav-${title && title.toLowerCase()}`}> <li key={`nav-${title && title.toLowerCase()}`}>
<Link to={href}> {MaybeIcon(icon, `Navigate to ${title}`)}
{/* {MaybeIcon(icon, `Navigate to ${title}`)} */} {href
{title} ? <IconButton to={href}>{title}</IconButton>
</Link> : <IconButton onClick={() => action()}>{title}</IconButton>}
</li> </li>
)) ))
} }
</DropdownWrapper> </DropdownWrapper>
); );
Dropdown.propTypes = { Dropdown.propTypes = {
align: PropTypes.oneOf(['left', 'right']), align: PropTypes.oneOf(['left', 'right']),
items: PropTypes.arrayOf(PropTypes.shape({ items: PropTypes.arrayOf(PropTypes.shape({

View file

@ -17,7 +17,7 @@ const IconButton = (props) => {
const Icon = icon; const Icon = icon;
return (<ButtonWrapper return (<ButtonWrapper
iconBefore={<Icon />} iconBefore={icon && <Icon />}
kind={Button.kinds.inline} kind={Button.kinds.inline}
focusable="false" focusable="false"
{...otherProps} {...otherProps}
@ -25,7 +25,11 @@ const IconButton = (props) => {
}; };
IconButton.propTypes = { IconButton.propTypes = {
icon: PropTypes.func.isRequired icon: PropTypes.func
};
IconButton.defaultProps = {
icon: null
}; };
export default IconButton; export default IconButton;

View file

@ -34,7 +34,7 @@ class App extends React.Component {
render() { render() {
return ( return (
<div className="app"> <div className="app">
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />} {false && this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
{this.props.children} {this.props.children}
</div> </div>
); );

View file

@ -46,18 +46,20 @@ const NavItem = styled.li`
position: relative; position: relative;
`; `;
const getNatOptions = (username = undefined) => const getNavOptions = (username = undefined, logoutUser = () => {}) =>
(username (username
? [ ? [
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', }, { icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
{ icon: PreferencesIcon, title: 'My Stuff', href: `/mobile/${username}/sketches` }, { icon: PreferencesIcon, title: 'My Stuff', href: `/mobile/${username}/sketches` },
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' }, { icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', }, { icon: PreferencesIcon, title: 'Original Editor', href: '/', },
{ icon: PreferencesIcon, title: 'Logout', action: logoutUser, },
] ]
: [ : [
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', }, { icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' }, { icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', }, { icon: PreferencesIcon, title: 'Original Editor', href: '/', },
{ icon: PreferencesIcon, title: 'Login', href: '/login', },
] ]
); );
@ -65,7 +67,7 @@ const MobileIDEView = (props) => {
const { const {
preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage, preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage,
selectedFile, updateFileContent, files, user, params, selectedFile, updateFileContent, files, user, params,
closeEditorOptions, showEditorOptions, closeEditorOptions, showEditorOptions, logoutUser,
startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console, startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console,
showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState
} = props; } = props;
@ -75,7 +77,7 @@ const MobileIDEView = (props) => {
const { username } = user; const { username } = user;
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown
items={getNatOptions(username)} items={getNavOptions(username, logoutUser)}
align="right" align="right"
/>); />);
@ -267,6 +269,8 @@ MobileIDEView.propTypes = {
username: PropTypes.string, username: PropTypes.string,
}).isRequired, }).isRequired,
logoutUser: 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({