2019-11-02 17:02:26 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2022-12-29 12:21:47 +08:00
|
|
|
import { Link } from '@gatsbyjs/reach-router';
|
2019-11-02 17:02:26 +08:00
|
|
|
import { siteRoot, gettext } from '../../../utils/constants';
|
|
|
|
|
|
|
|
const propTypes = {
|
2023-09-13 08:40:50 +08:00
|
|
|
email: PropTypes.string,
|
2025-02-19 11:49:16 +08:00
|
|
|
userName: PropTypes.string,
|
2019-11-02 17:02:26 +08:00
|
|
|
currentItem: PropTypes.string.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
class Nav extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.navItems = [
|
2024-07-18 11:58:42 +08:00
|
|
|
{ name: 'info', urlPart: '', text: gettext('Info') },
|
|
|
|
{ name: 'owned-repos', urlPart: 'owned-libraries', text: gettext('Owned Libraries') },
|
|
|
|
{ name: 'shared-repos', urlPart: 'shared-libraries', text: gettext('Shared Libraries') },
|
|
|
|
{ name: 'links', urlPart: 'shared-links', text: gettext('Shared Links') },
|
|
|
|
{ name: 'groups', urlPart: 'groups', text: gettext('Groups') }
|
2019-11-02 17:02:26 +08:00
|
|
|
];
|
2025-07-07 15:27:21 +08:00
|
|
|
this.itemRefs = [];
|
|
|
|
this.itemWidths = [];
|
2019-11-02 17:02:26 +08:00
|
|
|
}
|
|
|
|
|
2025-07-07 15:27:21 +08:00
|
|
|
componentDidMount() {
|
|
|
|
this.measureItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
measureItems = () => {
|
|
|
|
this.itemWidths = this.itemRefs.map(ref => ref?.offsetWidth || 77);
|
|
|
|
};
|
|
|
|
|
2019-11-02 17:02:26 +08:00
|
|
|
render() {
|
|
|
|
const { currentItem, email, userName } = this.props;
|
2025-07-07 15:27:21 +08:00
|
|
|
const activeIndex = this.navItems.findIndex(item => item.name === currentItem) || 0;
|
|
|
|
const indicatorWidth = this.itemWidths[activeIndex] || 56;
|
|
|
|
const indicatorOffset = this.itemWidths.slice(0, activeIndex).reduce((a, b) => a + b, 0);
|
2019-11-02 17:02:26 +08:00
|
|
|
return (
|
2019-11-12 14:43:33 +08:00
|
|
|
<div>
|
2019-11-02 17:02:26 +08:00
|
|
|
<div className="cur-view-path">
|
|
|
|
<h3 className="sf-heading"><Link to={`${siteRoot}sys/users/`}>{gettext('Users')}</Link> / {userName}</h3>
|
|
|
|
</div>
|
2025-07-07 15:27:21 +08:00
|
|
|
<ul
|
|
|
|
className="nav nav-indicator-container position-relative mx-4"
|
|
|
|
style={{
|
|
|
|
'--indicator-width': `${indicatorWidth}px`,
|
|
|
|
'--indicator-offset': `${indicatorOffset}px`
|
|
|
|
}}
|
|
|
|
>
|
2019-11-02 17:02:26 +08:00
|
|
|
{this.navItems.map((item, index) => {
|
|
|
|
return (
|
2025-07-07 15:27:21 +08:00
|
|
|
<li
|
|
|
|
className="nav-item"
|
|
|
|
key={index}
|
|
|
|
ref={el => this.itemRefs[index] = el}
|
|
|
|
>
|
|
|
|
<Link to={`${siteRoot}sys/user/${encodeURIComponent(email)}/${item.urlPart}`} className={`nav-link mx-3 ${currentItem == item.name ? ' active' : ''}`}>{item.text}</Link>
|
2019-11-02 17:02:26 +08:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Nav.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default Nav;
|