Rework user profile button
Summary: 1. fixed state when no connectivity by using a disabled button, now its styled correctly, (before it was tiny) 2. No need to show the user profile button as its own icon since log in is forced by flipper, so move log out into the more menu Reviewed By: mweststrate Differential Revision: D47720740 fbshipit-source-id: c7531a2a2897627c2627080179fd77adfed5c30c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d0e8114962
commit
83ecb4e256
@@ -21,14 +21,12 @@ import {getRenderHostInstance} from 'flipper-frontend-core';
|
|||||||
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
||||||
import {useDispatch, useStore} from '../utils/useStore';
|
import {useDispatch, useStore} from '../utils/useStore';
|
||||||
import config from '../fb-stubs/config';
|
import config from '../fb-stubs/config';
|
||||||
import {isConnected, currentUser, logoutUser} from '../fb-stubs/user';
|
import {currentUser, isConnected, logoutUser} from '../fb-stubs/user';
|
||||||
import {showLoginDialog} from '../chrome/fb-stubs/SignInSheet';
|
import {Badge, Button, Menu, Modal} from 'antd';
|
||||||
import {Avatar, Badge, Button, Menu, Modal, Popover, Tooltip} from 'antd';
|
|
||||||
import {
|
import {
|
||||||
BellOutlined,
|
BellOutlined,
|
||||||
BugOutlined,
|
BugOutlined,
|
||||||
LayoutOutlined,
|
LayoutOutlined,
|
||||||
LoginOutlined,
|
|
||||||
MobileOutlined,
|
MobileOutlined,
|
||||||
RocketOutlined,
|
RocketOutlined,
|
||||||
SettingOutlined,
|
SettingOutlined,
|
||||||
@@ -110,6 +108,8 @@ export const Navbar = withTrackingScope(function Navbar({
|
|||||||
)}
|
)}
|
||||||
</Layout.Horizontal>
|
</Layout.Horizontal>
|
||||||
<Layout.Horizontal style={{gap: 6, alignItems: 'center'}}>
|
<Layout.Horizontal style={{gap: 6, alignItems: 'center'}}>
|
||||||
|
<NoConnectivityWarning />
|
||||||
|
|
||||||
<NotificationButton
|
<NotificationButton
|
||||||
toplevelSelection={toplevelSelection}
|
toplevelSelection={toplevelSelection}
|
||||||
setToplevelSelection={setToplevelSelection}
|
setToplevelSelection={setToplevelSelection}
|
||||||
@@ -117,7 +117,7 @@ export const Navbar = withTrackingScope(function Navbar({
|
|||||||
<TroubleshootMenu setToplevelSelection={setToplevelSelection} />
|
<TroubleshootMenu setToplevelSelection={setToplevelSelection} />
|
||||||
<ExtrasMenu />
|
<ExtrasMenu />
|
||||||
<RightSidebarToggleButton />
|
<RightSidebarToggleButton />
|
||||||
{config.showLogin && <LoginConnectivityButton />}
|
|
||||||
<UpdateIndicator />
|
<UpdateIndicator />
|
||||||
</Layout.Horizontal>
|
</Layout.Horizontal>
|
||||||
</Layout.Horizontal>
|
</Layout.Horizontal>
|
||||||
@@ -336,10 +336,12 @@ export function NavbarButton({
|
|||||||
disabled = false,
|
disabled = false,
|
||||||
flipIcon = false,
|
flipIcon = false,
|
||||||
zIndex,
|
zIndex,
|
||||||
|
colorOverride,
|
||||||
}: {
|
}: {
|
||||||
icon: (props: any) => any;
|
icon: (props: any) => any;
|
||||||
label: string;
|
label: string;
|
||||||
// TODO remove optional
|
// TODO remove optional
|
||||||
|
colorOverride?: string;
|
||||||
zIndex?: number;
|
zIndex?: number;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
toggled?: boolean;
|
toggled?: boolean;
|
||||||
@@ -367,7 +369,7 @@ export function NavbarButton({
|
|||||||
disabled={disabled}>
|
disabled={disabled}>
|
||||||
<Icon
|
<Icon
|
||||||
style={{
|
style={{
|
||||||
color,
|
color: colorOverride || color,
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
transform: flipIcon ? 'scaleX(-1)' : undefined,
|
transform: flipIcon ? 'scaleX(-1)' : undefined,
|
||||||
}}
|
}}
|
||||||
@@ -376,7 +378,7 @@ export function NavbarButton({
|
|||||||
style={{
|
style={{
|
||||||
margin: 0,
|
margin: 0,
|
||||||
fontSize: theme.fontSize.small,
|
fontSize: theme.fontSize.small,
|
||||||
color: theme.textColorSecondary,
|
color: colorOverride || theme.textColorSecondary,
|
||||||
}}>
|
}}>
|
||||||
{label}
|
{label}
|
||||||
</span>
|
</span>
|
||||||
@@ -401,60 +403,21 @@ export function NavbarButton({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function LoginConnectivityButton() {
|
function NoConnectivityWarning() {
|
||||||
const loggedIn = useValue(currentUser());
|
|
||||||
const user = useStore((state) => state.user);
|
|
||||||
|
|
||||||
const profileUrl = user?.profile_picture?.uri;
|
|
||||||
const [showLogout, setShowLogout] = useState(false);
|
|
||||||
const onHandleVisibleChange = useCallback(
|
|
||||||
(visible) => setShowLogout(visible),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const connected = useValue(isConnected());
|
const connected = useValue(isConnected());
|
||||||
|
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<NavbarButton
|
||||||
placement="left"
|
disabled
|
||||||
title="No connection to intern, ensure you are VPN/Lighthouse for plugin updates and other features">
|
icon={WarningOutlined}
|
||||||
<WarningOutlined
|
colorOverride={theme.errorColor}
|
||||||
style={{color: theme.warningColor, fontSize: '20px'}}
|
label="No connectivity"
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return loggedIn ? (
|
return null;
|
||||||
<Popover
|
|
||||||
content={
|
|
||||||
<Button
|
|
||||||
block
|
|
||||||
style={{backgroundColor: theme.backgroundDefault}}
|
|
||||||
onClick={async () => {
|
|
||||||
onHandleVisibleChange(false);
|
|
||||||
await logoutUser();
|
|
||||||
}}>
|
|
||||||
Log Out
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
trigger="click"
|
|
||||||
placement="bottom"
|
|
||||||
visible={showLogout}
|
|
||||||
overlayStyle={{padding: 0}}
|
|
||||||
onVisibleChange={onHandleVisibleChange}>
|
|
||||||
<Layout.Container padv={theme.inlinePaddingV}>
|
|
||||||
<Avatar size={40} src={profileUrl} />
|
|
||||||
</Layout.Container>
|
|
||||||
</Popover>
|
|
||||||
) : (
|
|
||||||
<NavbarButton
|
|
||||||
icon={LoginOutlined}
|
|
||||||
label="Log In"
|
|
||||||
onClick={showLoginDialog}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const menu = css`
|
const menu = css`
|
||||||
@@ -593,6 +556,7 @@ function ExtrasMenu() {
|
|||||||
const settings = useStore((state) => state.settingsState);
|
const settings = useStore((state) => state.settingsState);
|
||||||
const {showWelcomeAtStartup} = settings;
|
const {showWelcomeAtStartup} = settings;
|
||||||
const [welcomeVisible, setWelcomeVisible] = useState(showWelcomeAtStartup);
|
const [welcomeVisible, setWelcomeVisible] = useState(showWelcomeAtStartup);
|
||||||
|
const loggedIn = useValue(currentUser());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -655,6 +619,11 @@ function ExtrasMenu() {
|
|||||||
<Menu.Item key="help" onClick={() => setWelcomeVisible(true)}>
|
<Menu.Item key="help" onClick={() => setWelcomeVisible(true)}>
|
||||||
Help
|
Help
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
{config.showLogin && loggedIn && (
|
||||||
|
<Menu.Item key="logout" onClick={async () => await logoutUser()}>
|
||||||
|
Logout
|
||||||
|
</Menu.Item>
|
||||||
|
)}
|
||||||
</Menu.SubMenu>
|
</Menu.SubMenu>
|
||||||
</Menu>
|
</Menu>
|
||||||
</NUX>
|
</NUX>
|
||||||
|
|||||||
Reference in New Issue
Block a user