1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-22 08:47:22 +00:00
seahub/frontend/src/components/file-chooser/searched-list-item.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-03-09 04:06:11 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
2019-03-09 04:06:11 +00:00
import { Utils } from '../../utils/utils';
const propTypes = {
currentItem: PropTypes.object,
onItemClick: PropTypes.func.isRequired,
onSearchedItemDoubleClick: PropTypes.func.isRequired,
item: PropTypes.object,
2019-03-09 04:06:11 +00:00
};
class SearchedListItem extends React.Component {
2019-03-09 04:06:11 +00:00
constructor(props) {
super(props);
this.state = {
highlight: false,
};
}
onMouseEnter = () => {
2024-07-18 03:58:42 +00:00
this.setState({ highlight: true });
};
2019-03-09 04:06:11 +00:00
onMouseLeave = () => {
2024-07-18 03:58:42 +00:00
this.setState({ highlight: false });
};
2019-03-09 04:06:11 +00:00
onClick = () => {
let item = this.props.item;
this.props.onItemClick(item);
};
2019-03-09 04:06:11 +00:00
searchItemDoubleClick = (e) => {
let item = this.props.item;
this.props.onSearchedItemDoubleClick(item);
};
2019-03-09 04:06:11 +00:00
render() {
let { item, currentItem } = this.props;
let folderIconUrl = item.link_content ? Utils.getFolderIconUrl(false, 192) : Utils.getDefaultLibIconUrl(false);
2024-08-05 13:04:31 +00:00
let fileIconUrl = item.is_dir ? folderIconUrl : Utils.getFileIconUrl(item.name);
2019-03-09 04:06:11 +00:00
return (
<tr
className={classnames('searched-list-item', {
'tr-highlight': this.state.highlight,
'tr-active': currentItem && item.repo_id === currentItem.repo_id && item.path === currentItem.path
})}
onClick={this.onClick}
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
onDoubleClick={this.searchItemDoubleClick}
>
2024-08-13 02:21:32 +00:00
<td className="text-center searched-item-icon">
<img className="item-img" src={fileIconUrl} alt="" width="24"/>
</td>
2024-08-13 02:21:32 +00:00
<td className='searched-item-link'>
<span className="item-link">{item.repo_name}/{item.link_content}</span>
</td>
2019-03-09 04:06:11 +00:00
</tr>
);
}
}
SearchedListItem.propTypes = propTypes;
export default SearchedListItem;