Skip to content

Commit 3db933f

Browse files
author
Mat Brown
committed
Current user menu uses createMenu
Final installation of porting all menus to `createMenu`, the current user “menu”. One change is that `createMenu` needs to pass the props to `<Label>` which seems entirely reasonable.
1 parent d269a9f commit 3db933f

4 files changed

Lines changed: 40 additions & 46 deletions

File tree

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,15 @@
1-
import classnames from 'classnames';
21
import React from 'react';
32
import PropTypes from 'prop-types';
43
import {t} from 'i18next';
54
import CurrentUserMenu from './CurrentUserMenu';
65

76
export default function CurrentUser({
8-
isOpen,
97
user,
10-
onClick,
11-
onClose,
128
onLogOut,
139
onStartLogIn,
1410
}) {
1511
if (user.authenticated) {
16-
const name = user.displayName;
17-
18-
return (
19-
<div
20-
className={classnames(
21-
'top-bar__menu-button',
22-
'top-bar__current-user',
23-
{'top-bar__menu-button_active': isOpen},
24-
)}
25-
onClick={onClick}
26-
>
27-
<img
28-
className="top-bar__avatar"
29-
src={user.avatarUrl}
30-
/>
31-
<span className="top-bar__username">{name}</span>
32-
<span className="top-bar__drop-down-button u__icon">
33-
&#xf0d7;
34-
</span>
35-
<CurrentUserMenu
36-
isOpen={isOpen}
37-
onClose={onClose}
38-
onLogOut={onLogOut}
39-
/>
40-
</div>
41-
);
12+
return <CurrentUserMenu user={user} onLogOut={onLogOut} />;
4213
}
4314
return (
4415
<div className="top-bar__current-user">
@@ -53,12 +24,9 @@ export default function CurrentUser({
5324
}
5425

5526
CurrentUser.propTypes = {
56-
isOpen: PropTypes.bool.isRequired,
5727
user: PropTypes.shape({
5828
authenticated: PropTypes.boolean,
5929
}).isRequired,
60-
onClick: PropTypes.func.isRequired,
61-
onClose: PropTypes.func.isRequired,
6230
onLogOut: PropTypes.func.isRequired,
6331
onStartLogIn: PropTypes.func.isRequired,
6432
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
export default function CurrentUserButton({user: {avatarUrl, displayName}}) {
5+
return (
6+
<div className="top-bar__current-user">
7+
<img
8+
className="top-bar__avatar"
9+
src={avatarUrl}
10+
/>
11+
<span className="top-bar__username">{displayName}</span>
12+
<span className="top-bar__drop-down-button u__icon">
13+
&#xf0d7;
14+
</span>
15+
</div>
16+
);
17+
}
18+
19+
CurrentUserButton.propTypes = {
20+
user: PropTypes.shape({
21+
avatarUrl: PropTypes.string.isRequired,
22+
displayName: PropTypes.string.isRequired,
23+
}).isRequired,
24+
};
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import {t} from 'i18next';
4+
import createMenu, {MenuItem} from './createMenu';
5+
import CurrentUserButton from './CurrentUserButton';
46

5-
export default function CurrentUserMenu({isOpen, onLogOut}) {
6-
if (!isOpen) {
7-
return null;
8-
}
7+
const CurrentUserMenu = createMenu({
8+
name: 'currentUser',
99

10-
return (
11-
<div className="top-bar__menu">
12-
<div className="top-bar__menu-item" onClick={onLogOut}>
10+
// eslint-disable-next-line react/prop-types
11+
renderItems({onLogOut}) {
12+
return (
13+
<MenuItem onClick={onLogOut}>
1314
{t('top-bar.session.log-out-prompt')}
14-
</div>
15-
</div>
16-
);
17-
}
15+
</MenuItem>
16+
);
17+
},
18+
})(CurrentUserButton);
1819

1920
CurrentUserMenu.propTypes = {
20-
isOpen: PropTypes.bool.isRequired,
2121
onLogOut: PropTypes.func.isRequired,
2222
};
23+
24+
export default CurrentUserMenu;

src/components/TopBar/createMenu.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default function createMenu({
8484
)}
8585
onClick={onToggle}
8686
>
87-
<Label />
87+
<Label {...props} />
8888
{menu}
8989
</div>
9090
);

0 commit comments

Comments
 (0)