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';
|
2023-10-11 15:58:06 +08:00
|
|
|
import classnames from 'classnames';
|
2019-01-10 16:36:54 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-09-29 18:32:53 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
item: PropTypes.object.isRequired,
|
|
|
|
onItemClickHandler: PropTypes.func.isRequired,
|
2023-10-11 15:58:06 +08:00
|
|
|
isHighlight: PropTypes.bool,
|
2023-10-11 20:39:41 +08:00
|
|
|
setRef: PropTypes.func,
|
2018-09-29 18:32:53 +08:00
|
|
|
};
|
2018-08-17 12:23:55 +08:00
|
|
|
|
|
|
|
class SearchResultItem extends React.Component {
|
|
|
|
|
2023-10-11 20:39:41 +08:00
|
|
|
static defaultProps = {
|
|
|
|
setRef: () => {},
|
|
|
|
};
|
|
|
|
|
2018-08-17 12:23:55 +08:00
|
|
|
onClickHandler = () => {
|
2024-07-01 16:36:26 +08:00
|
|
|
this.props.onItemClickHandler(this.props.item);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-08-17 12:23:55 +08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
let item = this.props.item;
|
2024-11-29 14:42:08 +08:00
|
|
|
let folderIconUrl = item.link_content ? Utils.getFolderIconUrl(false, 192) : Utils.getDefaultLibIconUrl();
|
2024-08-05 21:04:31 +08:00
|
|
|
let fileIconUrl = item.is_dir ? folderIconUrl : Utils.getFileIconUrl(item.name);
|
2024-01-02 12:14:16 +08:00
|
|
|
let showName = item.repo_name + '/' + item.link_content;
|
|
|
|
showName = showName.endsWith('/') ? showName.slice(0, showName.length - 1) : showName;
|
|
|
|
|
2023-11-15 17:46:00 +08:00
|
|
|
if (item.thumbnail_url) {
|
2021-01-21 11:51:16 +08:00
|
|
|
fileIconUrl = item.thumbnail_url;
|
|
|
|
}
|
|
|
|
|
2018-08-17 12:23:55 +08:00
|
|
|
return (
|
2023-10-11 15:58:06 +08:00
|
|
|
<li
|
2024-07-18 11:58:42 +08:00
|
|
|
className={classnames('search-result-item', { 'search-result-item-highlight': this.props.isHighlight })}
|
2023-10-11 15:58:06 +08:00
|
|
|
onClick={this.onClickHandler}
|
2023-10-11 20:39:41 +08:00
|
|
|
ref={ref => this.props.setRef(ref)}
|
2023-10-11 15:58:06 +08:00
|
|
|
>
|
|
|
|
<img className={item.link_content ? 'item-img' : 'lib-item-img'} src={fileIconUrl} alt="" />
|
2019-01-10 16:36:54 +08:00
|
|
|
<div className="item-content">
|
2019-03-19 11:39:33 +08:00
|
|
|
<div className="item-name ellipsis">{item.name}</div>
|
2024-01-02 12:14:16 +08:00
|
|
|
<div className="item-link ellipsis">{showName}</div>
|
2024-07-18 11:58:42 +08:00
|
|
|
<div className="item-text ellipsis" dangerouslySetInnerHTML={{ __html: item.content }}></div>
|
2019-01-10 16:36:54 +08:00
|
|
|
</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;
|