Skip to content

Commit 32efc40

Browse files
committed
✨ make login/logout options on dropdown
1 parent a28a4a5 commit 32efc40

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

client/components/Dropdown.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,27 @@ const DropdownWrapper = styled.ul`
5858
`;
5959

6060
// TODO: Add Icon to the left of the items in the menu
61-
// const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />;
61+
const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />;
6262

6363
const Dropdown = ({ items, align }) => (
6464
<DropdownWrapper align={align} >
6565
{/* className="nav__items-left" */}
66-
{items && items.map(({ title, icon, href }) => (
66+
{items && items.map(({
67+
title, icon, href, action
68+
}) => (
6769
<li key={`nav-${title && title.toLowerCase()}`}>
68-
<Link to={href}>
69-
{/* {MaybeIcon(icon, `Navigate to ${title}`)} */}
70-
{title}
71-
</Link>
70+
{MaybeIcon(icon, `Navigate to ${title}`)}
71+
{href
72+
? <IconButton to={href}>{title}</IconButton>
73+
: <IconButton onClick={() => action()}>{title}</IconButton>}
74+
7275
</li>
7376
))
7477
}
7578
</DropdownWrapper>
7679
);
7780

81+
7882
Dropdown.propTypes = {
7983
align: PropTypes.oneOf(['left', 'right']),
8084
items: PropTypes.arrayOf(PropTypes.shape({

client/components/mobile/IconButton.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ const IconButton = (props) => {
1717
const Icon = icon;
1818

1919
return (<ButtonWrapper
20-
iconBefore={<Icon />}
20+
iconBefore={icon && <Icon />}
2121
kind={Button.kinds.inline}
2222
focusable="false"
2323
{...otherProps}
2424
/>);
2525
};
2626

2727
IconButton.propTypes = {
28-
icon: PropTypes.func.isRequired
28+
icon: PropTypes.func
29+
};
30+
31+
IconButton.defaultProps = {
32+
icon: null
2933
};
3034

3135
export default IconButton;

client/modules/App/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class App extends React.Component {
3434
render() {
3535
return (
3636
<div className="app">
37-
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
37+
{false && this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
3838
{this.props.children}
3939
</div>
4040
);

client/modules/IDE/pages/MobileIDEView.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,28 @@ const NavItem = styled.li`
4646
position: relative;
4747
`;
4848

49-
const getNatOptions = (username = undefined) =>
49+
const getNavOptions = (username = undefined, logoutUser = () => {}) =>
5050
(username
5151
? [
5252
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
5353
{ icon: PreferencesIcon, title: 'My Stuff', href: `/mobile/${username}/sketches` },
5454
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
5555
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', },
56+
{ icon: PreferencesIcon, title: 'Logout', action: logoutUser, },
5657
]
5758
: [
5859
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
5960
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
6061
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', },
62+
{ icon: PreferencesIcon, title: 'Login', href: '/login', },
6163
]
6264
);
6365

6466
const MobileIDEView = (props) => {
6567
const {
6668
preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage,
6769
selectedFile, updateFileContent, files, user, params,
68-
closeEditorOptions, showEditorOptions,
70+
closeEditorOptions, showEditorOptions, logoutUser,
6971
startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console,
7072
showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState
7173
} = props;
@@ -75,7 +77,7 @@ const MobileIDEView = (props) => {
7577
const { username } = user;
7678

7779
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown
78-
items={getNatOptions(username)}
80+
items={getNavOptions(username, logoutUser)}
7981
align="right"
8082
/>);
8183

@@ -267,6 +269,8 @@ MobileIDEView.propTypes = {
267269
username: PropTypes.string,
268270
}).isRequired,
269271

272+
logoutUser: PropTypes.func.isRequired,
273+
270274
getProject: PropTypes.func.isRequired,
271275
clearPersistedState: PropTypes.func.isRequired,
272276
params: PropTypes.shape({

0 commit comments

Comments
 (0)