2018-09-18 20:57:17 -05:00
|
|
|
import React from 'react';
|
2018-09-29 18:32:53 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-10 16:36:54 +08:00
|
|
|
import { siteRoot } from '../../utils/constants';
|
|
|
|
import { Utils } from '../../utils/utils';
|
2018-09-29 18:32:53 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
item: PropTypes.object.isRequired,
|
|
|
|
onItemClickHandler: PropTypes.func.isRequired,
|
|
|
|
};
|
2018-08-17 12:23:55 +08:00
|
|
|
|
|
|
|
class SearchResultItem extends React.Component {
|
|
|
|
|
|
|
|
onClickHandler = () => {
|
|
|
|
var item = this.props.item;
|
2018-09-18 10:11:37 +08:00
|
|
|
this.props.onItemClickHandler(item);
|
2018-08-17 12:23:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let item = this.props.item;
|
2019-01-10 16:36:54 +08:00
|
|
|
let fileIconSize = Utils.isHiDPI() ? 48 : 24;
|
|
|
|
let fileIconUrl = item.is_dir ? siteRoot + 'media/img/folder-192.png' : Utils.getFileIconUrl(item.name, fileIconSize);
|
2018-08-17 12:23:55 +08:00
|
|
|
return (
|
|
|
|
<li className="search-result-item" onClick={this.onClickHandler}>
|
2019-01-10 16:36:54 +08:00
|
|
|
<img className="item-img" src={fileIconUrl} alt="" />
|
|
|
|
<div className="item-content">
|
|
|
|
<dt className="item-name ellipsis">{item.name}</dt>
|
|
|
|
<dd className="item-link ellipsis">{item.repo_name}/{item.link_content}</dd>
|
|
|
|
<dd className="item-text ellipsis" dangerouslySetInnerHTML={{__html: item.content}}></dd>
|
|
|
|
</div>
|
2018-08-17 12:23:55 +08:00
|
|
|
</li>
|
2018-09-29 18:32:53 +08:00
|
|
|
);
|
2018-08-17 12:23:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-29 18:32:53 +08:00
|
|
|
SearchResultItem.propTypes = propTypes;
|
|
|
|
|
2018-09-18 10:11:37 +08:00
|
|
|
export default SearchResultItem;
|