import React from 'react'; import PropTypes from 'prop-types'; import { siteRoot } from '../../utils/constants'; import { Utils } from '../../utils/utils'; const propTypes = { path: PropTypes.string.isRequired, dirent: PropTypes.object.isRequired, onDirentClick: PropTypes.func.isRequired, }; class WikiDirListItem extends React.Component { constructor(props) { super(props); this.state = { highlight: false, }; } onMouseEnter = () => { this.setState({highlight: true}); } onMouseLeave = () => { this.setState({highlight: false}); } onDirentClick = (e) => { e.preventDefault(); this.props.onDirentClick(this.props.dirent); } render() { let { path, dirent } = this.props; let href = siteRoot + 'wikis' + Utils.joinPath(path, dirent.name); let size = Utils.isHiDPI() ? 48 : 24; let iconUrl = ''; if (dirent.type === 'file') { iconUrl = Utils.getFileIconUrl(dirent.name, size); } else { let isReadOnly = false; if (dirent.permission === 'r' || dirent.permission === 'preview') { isReadOnly = true; } iconUrl = Utils.getFolderIconUrl({isReadOnly, size}); } return ( {dirent.name} {dirent.size} {dirent.mtime_relative} ); } } WikiDirListItem.propTypes = propTypes; export default WikiDirListItem;