From 6118dee3e70aedc8970ebfcf95892b5ac05821bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Thu, 28 Feb 2019 07:25:07 -0800 Subject: [PATCH] adding logged in user to sidebar Summary: Adding UI that shows when a user is logged in and allows the user to log out. Reviewed By: jknoxville Differential Revision: D14224401 fbshipit-source-id: 314a1c2f9a1021258e724e824be7577eb85d4b9e --- src/chrome/MainSidebar.js | 3 +- src/chrome/UserAccount.js | 89 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/chrome/UserAccount.js diff --git a/src/chrome/MainSidebar.js b/src/chrome/MainSidebar.js index c3546610d..d6903b278 100644 --- a/src/chrome/MainSidebar.js +++ b/src/chrome/MainSidebar.js @@ -32,6 +32,7 @@ import React from 'react'; import NotificationsHub from '../NotificationsHub.js'; import {selectPlugin} from '../reducers/connections.js'; import {setActiveSheet} from '../reducers/application.js'; +import UserAccount from './UserAccount.js'; import {connect} from 'react-redux'; const ListItem = styled('div')(({active}) => ({ @@ -107,7 +108,6 @@ const Plugins = styled(FlexColumn)({ const PluginDebugger = styled(FlexBox)(props => ({ color: colors.blackAlpha50, - borderTop: `1px solid ${colors.blackAlpha10}`, alignItems: 'center', padding: 10, flexShrink: 0, @@ -345,6 +345,7 @@ class MainSidebar extends PureComponent { />  Plugin not showing? + ); } diff --git a/src/chrome/UserAccount.js b/src/chrome/UserAccount.js new file mode 100644 index 000000000..d3ee26150 --- /dev/null +++ b/src/chrome/UserAccount.js @@ -0,0 +1,89 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import type {User} from '../reducers/user'; + +import {styled, PureComponent, FlexRow, Glyph, Text, colors} from 'flipper'; +import {logout} from '../reducers/user'; +import {connect} from 'react-redux'; +import electron from 'electron'; +import {findDOMNode} from 'react-dom'; + +const Container = styled(FlexRow)({ + alignItems: 'center', + padding: '5px 10px', + borderTop: `1px solid ${colors.blackAlpha10}`, + fontWeight: 500, +}); + +const ProfilePic = styled('img')({ + borderRadius: '999em', + flexShrink: 0, + width: 25, + marginRight: 6, +}); + +const UserName = styled(Text)({ + flexGrow: 1, + whiteSpace: 'nowrap', + overflow: 'hidden', + marginRight: 6, + textOverflow: 'ellipsis', +}); + +type UserAccountProps = {| + user: User, + logout: () => void, +|}; + +class UserAccount extends PureComponent { + _ref: ?Element; + + setRef = (ref: React.ElementRef<*>) => { + const element = findDOMNode(ref); + if (element instanceof HTMLElement) { + this._ref = element; + } + }; + + showDetails = () => { + const menuTemplate = [ + { + label: 'Sign Out', + click: this.props.logout, + }, + ]; + + const menu = electron.remote.Menu.buildFromTemplate(menuTemplate); + const {bottom, left} = this._ref ? this._ref.getBoundingClientRect() : {}; + menu.popup({ + window: electron.remote.getCurrentWindow(), + async: true, + x: parseInt(left, 10), + y: parseInt(bottom, 10) + 8, + }); + }; + + render() { + return this.props.user?.name ? ( + + + {this.props.user.name} + + + ) : null; + } +} + +export default connect( + ({user}) => ({ + user, + }), + { + logout, + }, +)(UserAccount);