1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 16:36:15 +00:00
Files
seahub/frontend/src/components/search/search-result-item.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-09-18 20:57:17 -05:00
import React from 'react';
import PropTypes from 'prop-types';
2023-10-11 15:58:06 +08:00
import classnames from 'classnames';
import { Utils } from '../../utils/utils';
const propTypes = {
item: PropTypes.object.isRequired,
onItemClickHandler: PropTypes.func.isRequired,
2023-10-11 15:58:06 +08:00
isHighlight: PropTypes.bool,
setRef: PropTypes.func,
};
2018-08-17 12:23:55 +08:00
class SearchResultItem extends React.Component {
static defaultProps = {
setRef: () => {},
};
2018-08-17 12:23:55 +08:00
onClickHandler = () => {
this.props.onItemClickHandler(this.props.item);
};
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) {
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}
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="" />
<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>
</div>
2018-08-17 12:23:55 +08:00
</li>
);
2018-08-17 12:23:55 +08:00
}
}
SearchResultItem.propTypes = propTypes;
export default SearchResultItem;