lbry-desktop/src/renderer/component/sideBar/view.jsx

94 lines
2.7 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as React from 'react';
import Button from 'component/button';
import classnames from 'classnames';
import * as NOTIFICATION_TYPES from 'constants/notification_types';
type SideBarLink = {
label: string,
path: string,
active: boolean,
icon: ?string,
subLinks: Array<SideBarLink>,
};
type Props = {
navLinks: {
primary: Array<SideBarLink>,
secondary: Array<SideBarLink>,
},
2018-04-23 07:13:00 +02:00
notifications: {
type: string,
},
2018-03-26 23:32:43 +02:00
};
const SideBar = (props: Props) => {
2018-06-25 08:07:45 +02:00
const { navLinks, notifications } = props;
2018-03-26 23:32:43 +02:00
const badges = Object.keys(notifications).length;
2018-03-26 23:32:43 +02:00
return (
<nav className="nav">
<div className="nav__links">
<ul className="nav__primary">
{navLinks.primary.map(({ label, path, active, icon }) => (
<li
key={path}
className={classnames('nav__link', {
'nav__link--active': active,
})}
>
<Button
navigate={path}
label={path === '/subscriptions' && badges ? `${label} (${badges})` : label}
icon={icon}
/>
</li>
))}
</ul>
<hr />
<ul>
{navLinks.secondary.map(({ label, path, active, icon, subLinks = [] }) => (
<li
key={label}
className={classnames('nav__link', {
'nav__link--active': active,
})}
>
<Button navigate={path} label={label} icon={icon} />
2018-04-23 07:13:00 +02:00
{
// The sublinks should be animated on open close
// Removing it because the current implementation with CSSTransitionGroup
// was really slow and looked pretty bad. Possible fix is upgrading to v2
// Not sure if that has better performance
}
2018-03-26 23:32:43 +02:00
{!!subLinks.length &&
active && (
2018-04-23 07:13:00 +02:00
<ul key="0" className="nav__sub-links">
{subLinks.map(({ label: subLabel, path: subPath, active: subLinkActive }) => (
<li
key={subPath}
className={classnames('nav__link nav__link--sub', {
'nav__link--active': subLinkActive,
})}
>
{subPath ? (
<Button navigate={subPath} label={subLabel} />
) : (
<span>{subLabel}</span>
)}
</li>
))}
</ul>
2018-03-26 23:32:43 +02:00
)}
</li>
))}
</ul>
</div>
</nav>
);
};
export default SideBar;