lbry-desktop/ui/component/header/view.jsx

202 lines
7.2 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
2018-11-26 02:21:25 +01:00
import * as ICONS from 'constants/icons';
2019-06-17 22:32:38 +02:00
import * as SETTINGS from 'constants/settings';
2019-08-21 22:54:44 +02:00
import * as PAGES from 'constants/pages';
import React, { Fragment } from 'react';
2019-06-17 22:32:38 +02:00
import { withRouter } from 'react-router';
2019-08-27 16:43:42 +02:00
import classnames from 'classnames';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
import LbcSymbol from 'component/common/lbc-symbol';
import WunderBar from 'component/wunderbar';
2019-06-17 22:32:38 +02:00
import Icon from 'component/common/icon';
import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button';
2019-08-27 16:43:42 +02:00
import Tooltip from 'component/common/tooltip';
// @if TARGET='app'
import { IS_MAC } from 'component/app/view';
// @endif
2019-10-09 18:34:18 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
balance: string,
2019-06-11 20:10:58 +02:00
roundedBalance: number,
2019-07-17 22:49:06 +02:00
history: { push: string => void, goBack: () => void, goForward: () => void },
2019-06-17 22:32:38 +02:00
currentTheme: string,
automaticDarkModeEnabled: boolean,
setClientSetting: (string, boolean | string) => void,
hideBalance: boolean,
2019-08-21 22:54:44 +02:00
email: ?string,
2019-10-28 15:04:37 +01:00
authHeader: boolean,
syncError: ?string,
2019-09-26 18:07:11 +02:00
signOut: () => void,
2018-03-26 23:32:43 +02:00
};
const Header = (props: Props) => {
2019-08-21 22:54:44 +02:00
const {
roundedBalance,
history,
setClientSetting,
currentTheme,
automaticDarkModeEnabled,
hideBalance,
email,
2019-10-28 15:04:37 +01:00
authHeader,
2019-09-26 18:07:11 +02:00
signOut,
syncError,
2019-08-21 22:54:44 +02:00
} = props;
2019-09-26 18:07:11 +02:00
const authenticated = Boolean(email);
// Sign out if they click the "x" when they are on the password prompt
const authHeaderAction = syncError ? { onClick: signOut } : { navigate: '/' };
const homeButtonNavigationProps = authHeader ? authHeaderAction : { navigate: '/' };
const closeButtonNavigationProps = authHeader ? authHeaderAction : { onClick: () => history.goBack() };
2018-03-26 23:32:43 +02:00
2019-06-17 22:32:38 +02:00
function handleThemeToggle() {
if (automaticDarkModeEnabled) {
setClientSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false);
}
if (currentTheme === 'dark') {
setClientSetting(SETTINGS.THEME, 'light');
} else {
setClientSetting(SETTINGS.THEME, 'dark');
}
}
2018-03-26 23:32:43 +02:00
2019-09-26 18:07:11 +02:00
function getWalletTitle() {
return hideBalance ? (
__('Wallet')
) : (
<React.Fragment>
{roundedBalance} <LbcSymbol />
</React.Fragment>
);
2019-08-21 22:54:44 +02:00
}
2017-06-06 23:19:12 +02:00
return (
<header
className={classnames('header', {
2019-10-28 15:04:37 +01:00
'header--minimal': authHeader,
// @if TARGET='app'
'header--mac': IS_MAC,
// @endif
})}
>
2019-06-11 20:10:58 +02:00
<div className="header__contents">
<div className="header__navigation">
2019-09-30 23:48:30 +02:00
<Button
className="header__navigation-item header__navigation-item--lbry"
label={__('LBRY')}
icon={ICONS.LBRY}
2019-10-28 15:04:37 +01:00
{...homeButtonNavigationProps}
2019-09-30 23:48:30 +02:00
/>
2019-08-27 16:43:42 +02:00
{/* @if TARGET='app' */}
2019-10-28 15:04:37 +01:00
{!authHeader && (
2019-08-27 16:43:42 +02:00
<div className="header__navigation-arrows">
<Button
className="header__navigation-item header__navigation-item--back"
description={__('Navigate back')}
onClick={() => history.goBack()}
icon={ICONS.ARROW_LEFT}
iconSize={18}
/>
<Button
className="header__navigation-item header__navigation-item--forward"
description={__('Navigate forward')}
onClick={() => history.goForward()}
icon={ICONS.ARROW_RIGHT}
iconSize={18}
/>
</div>
)}
{/* @endif */}
2019-10-28 15:04:37 +01:00
{!authHeader && <WunderBar />}
2019-06-11 20:10:58 +02:00
</div>
2019-08-27 16:43:42 +02:00
2019-10-28 15:04:37 +01:00
{!authHeader ? (
2019-09-26 18:07:11 +02:00
<div className={classnames('header__menu', { 'header__menu--small': IS_WEB && !authenticated })}>
{!IS_WEB || authenticated ? (
2019-08-27 16:43:42 +02:00
<Fragment>
<Menu>
2019-09-26 18:07:11 +02:00
<MenuButton className="header__navigation-item menu__title">{getWalletTitle()}</MenuButton>
2019-08-27 16:43:42 +02:00
<MenuList className="menu__list--header">
2019-09-26 18:07:11 +02:00
<MenuItem className="menu__link" onSelect={() => history.push(`/$/${PAGES.WALLET}`)}>
2019-08-27 16:43:42 +02:00
<Icon aria-hidden icon={ICONS.WALLET} />
{__('Wallet')}
</MenuItem>
2019-09-26 18:07:11 +02:00
<MenuItem className="menu__link" onSelect={() => history.push(`/$/${PAGES.REWARDS}`)}>
2019-08-27 16:43:42 +02:00
<Icon aria-hidden icon={ICONS.FEATURED} />
{__('Rewards')}
</MenuItem>
</MenuList>
</Menu>
<Menu>
<MenuButton className="header__navigation-item menu__title">
<Icon size={18} icon={ICONS.ACCOUNT} />
</MenuButton>
<MenuList className="menu__list--header">
2019-09-26 18:07:11 +02:00
<MenuItem className="menu__link" onSelect={() => history.push(`/$/${PAGES.ACCOUNT}`)}>
2019-08-27 16:43:42 +02:00
<Icon aria-hidden icon={ICONS.OVERVIEW} />
{__('Overview')}
</MenuItem>
2019-09-26 18:07:11 +02:00
<MenuItem className="menu__link" onSelect={() => history.push(`/$/${PAGES.PUBLISH}`)}>
2019-08-27 16:43:42 +02:00
<Icon aria-hidden icon={ICONS.PUBLISH} />
{__('Publish')}
</MenuItem>
2019-09-26 18:07:11 +02:00
{authenticated ? (
2019-08-27 16:43:42 +02:00
<MenuItem className="menu__link" onSelect={signOut}>
<Icon aria-hidden icon={ICONS.SIGN_OUT} />
{__('Sign Out')}
</MenuItem>
) : (
<MenuItem className="menu__link" onSelect={() => history.push(`/$/${PAGES.AUTH}`)}>
<Icon aria-hidden icon={ICONS.SIGN_IN} />
{__('Sign In')}
</MenuItem>
2019-08-27 16:43:42 +02:00
)}
</MenuList>
</Menu>
<Menu>
<MenuButton className="header__navigation-item menu__title">
<Icon size={18} icon={ICONS.SETTINGS} />
</MenuButton>
<MenuList className="menu__list--header">
2019-09-26 18:07:11 +02:00
<MenuItem className="menu__link" onSelect={() => history.push(`/$/${PAGES.SETTINGS}`)}>
2019-08-27 16:43:42 +02:00
<Icon aria-hidden tootlip icon={ICONS.SETTINGS} />
{__('Settings')}
</MenuItem>
2019-09-26 18:07:11 +02:00
<MenuItem className="menu__link" onSelect={() => history.push(`/$/${PAGES.HELP}`)}>
2019-08-27 16:43:42 +02:00
<Icon aria-hidden icon={ICONS.HELP} />
{__('Help')}
</MenuItem>
<MenuItem className="menu__link" onSelect={handleThemeToggle}>
<Icon icon={currentTheme === 'light' ? ICONS.DARK : ICONS.LIGHT} />
{currentTheme === 'light' ? __('Dark') : __('Light')}
2019-08-27 16:43:42 +02:00
</MenuItem>
</MenuList>
</Menu>
</Fragment>
) : (
2019-09-26 18:07:11 +02:00
<Button navigate={`/$/${PAGES.AUTH}`} button="primary" label={__('Sign In')} />
2019-08-27 16:43:42 +02:00
)}
</div>
) : (
<div className="header__menu">
2019-10-28 15:04:37 +01:00
{/* Add an empty span here so we can use the same style as above */}
{/* This pushes the close button to the right side */}
<span />
2019-08-27 16:43:42 +02:00
<Tooltip label={__('Go Back')}>
2019-10-28 15:04:37 +01:00
<Button icon={ICONS.REMOVE} {...closeButtonNavigationProps} />
2019-08-27 16:43:42 +02:00
</Tooltip>
</div>
)}
2017-06-06 23:19:12 +02:00
</div>
</header>
);
2017-06-06 06:21:55 +02:00
};
2019-06-17 22:32:38 +02:00
export default withRouter(Header);