import React from 'react'; import PropTypes from 'prop-types'; import DirentListView from './dirent-list-view'; const propTypes = { selectedPath: PropTypes.string, selectedRepo: PropTypes.object, repo: PropTypes.object.isRequired, initToShowChildren: PropTypes.bool.isRequired, onDirentItemClick: PropTypes.func.isRequired, onRepoItemClick: PropTypes.func.isRequired, }; class RepoListItem extends React.Component { constructor(props) { super(props); this.state = { isShowChildren: this.props.initToShowChildren, }; } onToggleClick = () => { this.setState({isShowChildren: !this.state.isShowChildren}); } onDirentItemClick = (filePath) => { let repo = this.props.repo; this.props.onDirentItemClick(repo, filePath); } onRepoItemClick = () => { this.props.onRepoItemClick(this.props.repo); } render() { let repoActive = false; let isCurrentRepo = this.props.selectedRepo && (this.props.repo.repo_id === this.props.selectedRepo.repo_id); if (isCurrentRepo && !this.props.selectedPath) { repoActive = true; } return (
  • {this.props.repo.repo_name} {this.state.isShowChildren && ( )}
  • ); } } RepoListItem.propTypes = propTypes; export default RepoListItem;