2018-02-16 17:19:57 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Li
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-02-19 13:48:02 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
|
|
|
import cn from 'classnames';
|
2018-02-16 17:19:57 +01:00
|
|
|
|
2018-02-19 14:23:47 +01:00
|
|
|
import FileIcon from 'components/FileIcon';
|
2018-02-19 15:14:32 +01:00
|
|
|
import IcoContainer from 'components/IcoContainer';
|
|
|
|
import PopUpWarning from 'components/PopUpWarning';
|
2018-02-19 14:23:47 +01:00
|
|
|
|
2018-02-16 17:19:57 +01:00
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2018-02-22 12:08:11 +01:00
|
|
|
/* eslint-disable react/no-string-refs */
|
2018-02-16 17:19:57 +01:00
|
|
|
class Li extends React.Component {
|
2018-02-19 13:48:02 +01:00
|
|
|
state = { isOpen: false, copied: false };
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (prevState.copied !== this.state.copied && this.state.copied) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({ copied: false });
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:14:32 +01:00
|
|
|
handleClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.refs.aTag.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDelete = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.context.deleteData(this.props.item);
|
|
|
|
}
|
|
|
|
|
2018-02-19 13:48:02 +01:00
|
|
|
renderLiCopied = () => (
|
|
|
|
<li className={cn(styles.liWrapper, styles.copied)}>
|
|
|
|
<div>
|
|
|
|
<div className={styles.checked}>
|
|
|
|
<div />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<FormattedMessage id="upload.Li.linkCopied" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
2018-02-16 17:19:57 +01:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { item } = this.props;
|
|
|
|
|
2018-02-19 13:48:02 +01:00
|
|
|
if (this.state.copied) {
|
|
|
|
return this.renderLiCopied();
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:14:32 +01:00
|
|
|
const icons = [
|
2018-02-23 15:28:01 +01:00
|
|
|
// {
|
|
|
|
// icoType: item.private ? 'lock' : 'unlock',
|
|
|
|
// onClick: () => {},
|
|
|
|
// },
|
2018-02-19 15:14:32 +01:00
|
|
|
{
|
|
|
|
icoType: 'eye',
|
|
|
|
onClick: this.handleClick,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icoType: 'trash',
|
|
|
|
onClick: () => this.setState({ isOpen: true }),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-02-16 17:19:57 +01:00
|
|
|
return (
|
2018-02-19 13:48:02 +01:00
|
|
|
<CopyToClipboard text={item.url} onCopy={() => this.setState({copied: true})}>
|
|
|
|
<li className={styles.liWrapper}>
|
2018-02-22 18:24:17 +01:00
|
|
|
<a href={item.url} target="_blank" style={{ display: 'none' }} ref="aTag">nothing</a>
|
2018-02-19 13:48:02 +01:00
|
|
|
<div className={styles.liContainer}>
|
2018-02-23 12:21:57 +01:00
|
|
|
<div>
|
|
|
|
<div />
|
|
|
|
<FileIcon fileType={item.ext} />
|
|
|
|
</div>
|
|
|
|
{['hash', 'name', 'updatedAt', 'size', 'relatedTo', ''].map((value, key) => {
|
|
|
|
// if (key === 0) {
|
|
|
|
// return <FileIcon key={key} fileType={item[value]} />;
|
|
|
|
// }
|
2018-02-16 17:19:57 +01:00
|
|
|
|
2018-02-23 11:06:30 +01:00
|
|
|
if (value !== '') {
|
2018-02-19 13:48:02 +01:00
|
|
|
return (
|
2018-02-22 18:24:17 +01:00
|
|
|
<div key={key} className={styles.truncate}>{item[value]}</div>
|
2018-02-19 13:48:02 +01:00
|
|
|
);
|
|
|
|
}
|
2018-02-19 15:14:32 +01:00
|
|
|
|
2018-02-22 12:08:11 +01:00
|
|
|
return <IcoContainer key={key} icons={icons} />;
|
2018-02-19 13:48:02 +01:00
|
|
|
})}
|
|
|
|
</div>
|
2018-02-19 15:14:32 +01:00
|
|
|
<PopUpWarning
|
|
|
|
isOpen={this.state.isOpen}
|
|
|
|
onConfirm={this.handleDelete}
|
|
|
|
toggleModal={() => this.setState({ isOpen: false })}
|
|
|
|
/>
|
2018-02-19 13:48:02 +01:00
|
|
|
</li>
|
|
|
|
</CopyToClipboard>
|
2018-02-16 17:19:57 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:14:32 +01:00
|
|
|
Li.contextTypes = {
|
|
|
|
deleteData: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-02-16 17:19:57 +01:00
|
|
|
Li.defaultProps = {
|
|
|
|
item: {
|
|
|
|
type: 'pdf',
|
|
|
|
hash: '1234',
|
|
|
|
name: 'avatar.pdf',
|
|
|
|
updated: '20/11/2017 19:29:54',
|
|
|
|
size: '24 B',
|
|
|
|
relatedTo: 'John Doe',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-02-22 12:08:11 +01:00
|
|
|
Li.propTypes = {
|
2018-02-16 17:19:57 +01:00
|
|
|
item: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Li;
|