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