2018-12-03 16:21:09 +08:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-04-19 14:51:41 +08:00
|
|
|
import { DropdownToggle, Dropdown, DropdownMenu, DropdownItem } from 'reactstrap';
|
2022-12-29 12:21:47 +08:00
|
|
|
import { Link, navigate } from '@gatsbyjs/reach-router';
|
2024-04-19 14:51:41 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-12-08 10:29:13 +00:00
|
|
|
import { siteRoot, gettext } from '../../utils/constants';
|
2018-12-07 10:36:59 +08:00
|
|
|
import ModalPortal from '../modal-portal';
|
|
|
|
import CreateRepoDialog from '../dialog/create-repo-dialog';
|
2018-12-03 16:21:09 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
2018-12-07 10:36:59 +08:00
|
|
|
onCreateRepo: PropTypes.func.isRequired,
|
2024-04-19 14:51:41 +08:00
|
|
|
moreShown: PropTypes.bool
|
2018-12-03 16:21:09 +08:00
|
|
|
};
|
|
|
|
|
2024-04-19 14:51:41 +08:00
|
|
|
class MyLibsToolbar extends React.Component {
|
2020-11-02 13:56:35 +08:00
|
|
|
|
2018-12-07 10:36:59 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2024-04-19 14:51:41 +08:00
|
|
|
isCreateRepoDialogOpen: false,
|
2018-12-08 10:29:13 +00:00
|
|
|
isOpen: false,
|
2018-12-07 10:36:59 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreateRepo = (repo) => {
|
|
|
|
this.props.onCreateRepo(repo);
|
|
|
|
this.onCreateToggle();
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-07 10:36:59 +08:00
|
|
|
|
|
|
|
onCreateToggle = () => {
|
2024-04-19 14:51:41 +08:00
|
|
|
this.setState({isCreateRepoDialogOpen: !this.state.isCreateRepoDialogOpen});
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-03 16:21:09 +08:00
|
|
|
|
2018-12-08 10:29:13 +00:00
|
|
|
toggleMore = () => {
|
|
|
|
this.setState({ isOpen: !this.state.isOpen });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-08 10:29:13 +00:00
|
|
|
|
2021-09-26 15:50:28 +08:00
|
|
|
onDropdownToggleKeyDown = (e) => {
|
|
|
|
if (e.key == 'Enter' || e.key == 'Space') {
|
|
|
|
this.toggleMore();
|
|
|
|
}
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2021-09-26 15:50:28 +08:00
|
|
|
|
2021-09-26 14:12:14 +08:00
|
|
|
visitDeletedviaKey = (e) => {
|
|
|
|
if (e.key == 'Enter' || e.key == 'Space') {
|
|
|
|
navigate(`${siteRoot}my-libs/deleted/`);
|
|
|
|
}
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2021-09-26 14:12:14 +08:00
|
|
|
|
2018-12-03 16:21:09 +08:00
|
|
|
render() {
|
2024-04-19 14:51:41 +08:00
|
|
|
const { moreShown = false } = this.props;
|
2018-12-03 16:21:09 +08:00
|
|
|
return (
|
2018-12-07 10:36:59 +08:00
|
|
|
<Fragment>
|
2024-04-19 14:51:41 +08:00
|
|
|
{Utils.isDesktop() ? (
|
|
|
|
<div className="operation">
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('New Library')} onClick={this.onCreateToggle}>
|
2024-06-28 08:39:44 +08:00
|
|
|
<i className="sf3-font sf3-font-enlarge text-secondary mr-1"></i>{gettext('New Library')}
|
2024-04-19 14:51:41 +08:00
|
|
|
</button>
|
|
|
|
{moreShown &&
|
2019-08-22 20:23:08 +08:00
|
|
|
<Dropdown isOpen={this.state.isOpen} toggle={this.toggleMore}>
|
2021-09-26 15:50:28 +08:00
|
|
|
<DropdownToggle className='btn btn-secondary operation-item' onKeyDown={this.onDropdownToggleKeyDown}>
|
2019-08-22 20:23:08 +08:00
|
|
|
{gettext('More')}
|
|
|
|
</DropdownToggle>
|
|
|
|
<DropdownMenu>
|
2021-09-26 14:12:14 +08:00
|
|
|
<DropdownItem className="link-dropdown-container" onKeyDown={this.visitDeletedviaKey}>
|
2019-08-22 20:23:08 +08:00
|
|
|
<Link className="link-dropdown-item" to={siteRoot + 'my-libs/deleted/'}>{gettext('Deleted Libraries')}</Link>
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
2024-04-19 14:51:41 +08:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<span className="sf2-icon-plus mobile-toolbar-icon" title={gettext('New Library')} onClick={this.onCreateToggle}></span>
|
|
|
|
)}
|
|
|
|
{this.state.isCreateRepoDialogOpen && (
|
2018-12-07 10:36:59 +08:00
|
|
|
<ModalPortal>
|
2020-11-02 13:56:35 +08:00
|
|
|
<CreateRepoDialog
|
2024-04-19 14:51:41 +08:00
|
|
|
libraryType='mine'
|
2018-12-07 10:36:59 +08:00
|
|
|
onCreateRepo={this.onCreateRepo}
|
|
|
|
onCreateToggle={this.onCreateToggle}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
|
|
|
)}
|
|
|
|
</Fragment>
|
2018-12-03 16:21:09 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-19 14:51:41 +08:00
|
|
|
MyLibsToolbar.propTypes = propTypes;
|
2018-12-03 16:21:09 +08:00
|
|
|
|
2024-04-19 14:51:41 +08:00
|
|
|
export default MyLibsToolbar;
|