import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { withUnstatedContainers } from '../UnstatedUtils'; import AppContainer from '../../services/AppContainer'; import NavigationContainer from '../../services/NavigationContainer'; class SidebarNav extends React.Component { static propTypes = { onItemSelected: PropTypes.func, }; state = { }; itemSelectedHandler = (contentsId) => { const { navigationContainer, onItemSelected } = this.props; if (onItemSelected != null) { onItemSelected(contentsId); } navigationContainer.setState({ sidebarContentsId: contentsId }); } PrimaryItem = ({ id, label, iconName }) => { const { sidebarContentsId } = this.props.navigationContainer.state; const isSelected = sidebarContentsId === id; return ( ); } SecondaryItem({ label, iconName, href, isBlank, }) { return ( {iconName} ); } generateIconFactory(classNames) { return () => ; } render() { const { isAdmin, currentUsername, isSharedUser } = this.props.appContainer; const isLoggedIn = currentUsername != null; const { PrimaryItem, SecondaryItem } = this; return (
{!isSharedUser && } {!isSharedUser && } {/* */} {/* */}
{isAdmin && } {isLoggedIn && } {isLoggedIn && }
); } } SidebarNav.propTypes = { appContainer: PropTypes.instanceOf(AppContainer).isRequired, navigationContainer: PropTypes.instanceOf(NavigationContainer).isRequired, }; /** * Wrapper component for using unstated */ const SidebarNavWrapper = withUnstatedContainers(SidebarNav, [AppContainer, NavigationContainer]); export default withTranslation()(SidebarNavWrapper);