2018-09-29 18:32:53 +08:00
|
|
|
import React from 'react';
|
2018-10-16 18:19:51 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2018-11-29 17:55:14 +08:00
|
|
|
import { siteRoot } from '../../utils/constants';
|
2019-01-11 15:37:02 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-09-29 15:47:53 +08:00
|
|
|
|
2018-10-16 18:19:51 +08:00
|
|
|
const propTypes = {
|
2019-01-28 16:48:03 +08:00
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
dirent: PropTypes.object.isRequired,
|
|
|
|
onDirentClick: PropTypes.func.isRequired,
|
2018-10-16 18:19:51 +08:00
|
|
|
};
|
|
|
|
|
2019-01-28 16:48:03 +08:00
|
|
|
class WikiDirListItem extends React.Component {
|
2018-09-04 17:16:50 +08:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-09-29 15:47:53 +08:00
|
|
|
highlight: false,
|
|
|
|
};
|
2018-09-04 17:16:50 +08:00
|
|
|
}
|
|
|
|
|
2018-09-18 20:57:17 -05:00
|
|
|
onMouseEnter = () => {
|
2018-10-25 13:36:06 +08:00
|
|
|
this.setState({highlight: true});
|
2018-09-29 15:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-18 20:57:17 -05:00
|
|
|
onMouseLeave = () => {
|
2018-10-25 13:36:06 +08:00
|
|
|
this.setState({highlight: false});
|
2018-09-18 20:57:17 -05:00
|
|
|
}
|
|
|
|
|
2019-01-28 16:48:03 +08:00
|
|
|
onDirentClick = (e) => {
|
2018-11-30 11:52:19 +08:00
|
|
|
e.preventDefault();
|
2019-01-28 16:48:03 +08:00
|
|
|
this.props.onDirentClick(this.props.dirent);
|
2018-09-04 17:16:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-01-28 16:48:03 +08:00
|
|
|
let { path, dirent } = this.props;
|
|
|
|
let href = siteRoot + 'wikis' + Utils.joinPath(path, dirent.name);
|
2019-01-29 15:22:02 +08:00
|
|
|
let iconUrl = Utils.getDirentIcon(dirent);
|
2019-01-11 15:37:02 +08:00
|
|
|
|
2018-09-04 17:16:50 +08:00
|
|
|
return (
|
2018-10-25 13:36:06 +08:00
|
|
|
<tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
2018-12-28 11:12:24 +08:00
|
|
|
<td className="text-center">
|
2019-01-11 15:37:02 +08:00
|
|
|
<img src={iconUrl} width="24" alt="" />
|
2018-09-04 17:16:50 +08:00
|
|
|
</td>
|
2018-11-30 11:52:19 +08:00
|
|
|
<td className="name">
|
2019-01-28 16:48:03 +08:00
|
|
|
<a href={href} onClick={this.onDirentClick}>{dirent.name}</a>
|
2018-11-30 11:52:19 +08:00
|
|
|
</td>
|
2019-01-28 16:48:03 +08:00
|
|
|
<td>{dirent.size}</td>
|
2019-01-29 11:03:43 +08:00
|
|
|
<td title={dirent.mtime_relative}>{dirent.mtime_relative}</td>
|
2018-09-04 17:16:50 +08:00
|
|
|
</tr>
|
2018-09-29 18:32:53 +08:00
|
|
|
);
|
2018-09-04 17:16:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 16:48:03 +08:00
|
|
|
WikiDirListItem.propTypes = propTypes;
|
2018-10-16 18:19:51 +08:00
|
|
|
|
2019-01-28 16:48:03 +08:00
|
|
|
export default WikiDirListItem;
|