import React from 'react';
import PropTypes from 'prop-types';
import { Link } from '@reach/router';
import Group from '../models/group';
import { gettext, siteRoot, enableWiki, canAddRepo, canGenerateShareLink, canGenerateUploadLink } from '../utils/constants';
import { seafileAPI } from '../utils/seafile-api';
import { Badge } from 'reactstrap';
import { canViewOrg } from '../utils/constants';
const propTypes = {
currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
tabItemClick: PropTypes.func.isRequired,
draftCounts: PropTypes.number,
};
class MainSideNav extends React.Component {
constructor(props) {
super(props);
this.state = {
groupsExtended: false,
sharedExtended: false,
closeSideBar:false,
groupItems: [],
};
this.listHeight = 24; //for caculate tabheight
this.groupsHeight = 0;
this.adminHeight = 0;
}
grpsExtend = () => {
this.setState({
groupsExtended: !this.state.groupsExtended,
});
this.loadGroups();
}
shExtend = () => {
this.setState({
sharedExtended: !this.state.sharedExtended,
});
}
loadGroups = () => {
let _this = this;
seafileAPI.listGroups().then(res =>{
let groupList = res.data.map(item => {
let group = new Group(item);
return group;
});
this.groupsHeight = (groupList.length + 1) * _this.listHeight;
_this.setState({
groupItems: groupList
});
});
}
tabItemClick = (param, id) => {
this.props.tabItemClick(param, id);
}
getActiveClass = (tab) => {
return this.props.currentTab === tab ? 'active' : '';
}
renderSharedGroups() {
let style = {height: 0};
if (this.state.groupsExtended) {
style = {height: this.groupsHeight};
}
return (
-
this.tabItemClick('groups')}>
#
{gettext('All Groups')}
{this.state.groupItems.map(item => {
return (
-
this.tabItemClick(item.name, item.id)}>
#
{item.name}
);
})}
);
}
renderSharedAdmin() {
let height = 0;
if (this.state.sharedExtended) {
if (!this.adminHeight) {
this.adminHeight = 3 * this.listHeight;
}
height = this.adminHeight;
}
let style = {height: height};
let linksNavItem = null;
if (canGenerateShareLink) {
linksNavItem = (
this.tabItemClick('share-admin-share-links')}>
#
{gettext('Links')}
);
} else if (canGenerateUploadLink) {
linksNavItem = (
this.tabItemClick('share-admin-upload-links')}>
#
{gettext('Links')}
);
}
return (
{canAddRepo && (
-
this.tabItemClick('share-admin-libs')}>
#
{gettext('Libraries')}
)}
-
this.tabItemClick('share-admin-folders')}>
#
{gettext('Folders')}
{linksNavItem}
);
}
render() {
return (
{gettext('Files')}
{canAddRepo && (
-
this.tabItemClick('my-libs')}>
{gettext('My Libraries')}
)}
-
this.tabItemClick('shared-libs')}>
{gettext('Shared with me')}
{ canViewOrg &&
- this.tabItemClick('org')}>
{gettext('Shared with all')}
}
-
{gettext('Shared with groups')}
{this.renderSharedGroups()}
{gettext('Tools')}
-
this.tabItemClick('starred')}>
{gettext('Favorites')}
-
this.tabItemClick('dashboard')}>
{gettext('Activities')}
{enableWiki &&
-
this.tabItemClick('wikis')}>
{gettext('Wikis')}
}
-
this.tabItemClick('linked-devices')}>
{gettext('Linked Devices')}
- this.tabItemClick('drafts')}>
{gettext('Drafts')}
{this.props.draftCounts === 0 ? '' : {this.props.draftCounts}}
-
{gettext('Share Admin')}
{this.renderSharedAdmin()}
);
}
}
MainSideNav.propTypes = propTypes;
export default MainSideNav;