import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import {
GlobalNav,
} from '@atlaskit/navigation-next';
import { createSubscribedElement } from '../UnstatedUtils';
import AppContainer from '../../services/AppContainer';
class SidebarNav extends React.Component {
static propTypes = {
currentContentsId: PropTypes.string,
onItemSelected: PropTypes.func,
};
state = {
};
itemSelectedHandler = (contentsId) => {
const { onItemSelected } = this.props;
if (onItemSelected != null) {
onItemSelected(contentsId);
}
}
generatePrimaryItemObj(id, label, iconClassNames) {
const isSelected = this.props.currentContentsId === id;
return {
id,
component: ({ className }) => (
),
};
}
generateSecondaryItemObj(id, label, iconClassNames, href, isBlank, isHiddenOnLargeDevice) {
return {
id,
component: ({ className }) => (
),
};
}
generateIconFactory(classNames) {
return () => ;
}
render() {
const { isAdmin, currentUsername } = this.props.appContainer;
const primaryItems = [
this.generatePrimaryItemObj('custom', 'Custom Sidebar', 'fa fa-code'),
this.generatePrimaryItemObj('recent', 'Recent Changes', 'icon-clock'),
// this.generatePrimaryItemObj('tag', 'Tags', 'icon-tag'),
// this.generatePrimaryItemObj('favorite', 'Favorite', 'icon-star'),
];
const secondaryItems = [
this.generateSecondaryItemObj('draft', 'Draft', 'icon-docs', `/user/${currentUsername}#user-draft-list`),
this.generateSecondaryItemObj('help', 'Help', 'icon-question', 'https://docs.growi.org', true),
this.generateSecondaryItemObj('trash', 'Trash', 'icon-trash', '/trash'),
];
if (isAdmin) {
secondaryItems.unshift( // add to the beginning
this.generateSecondaryItemObj('admin', 'Admin', 'icon-settings', '/admin', false, true),
);
}
return (
);
}
}
SidebarNav.propTypes = {
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
};
/**
* Wrapper component for using unstated
*/
const SidebarNavWrapper = (props) => {
return createSubscribedElement(SidebarNav, props, [AppContainer]);
};
export default withTranslation()(SidebarNavWrapper);