77 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-02-16 16:53:01 +01:00
/**
*
* ListHeader
*
*/
import React from 'react';
import { FormattedMessage } from 'react-intl';
import cn from 'classnames';
import PropTypes from 'prop-types';
2018-02-16 16:53:01 +01:00
2018-02-22 12:08:11 +01:00
// import InputCheckBox from 'components/InputCheckbox';
2018-02-16 16:53:01 +01:00
import styles from './styles.scss';
function ListHeader({ changeSort, sort }) {
2018-02-16 16:53:01 +01:00
const titles = [
'hash',
'name',
'updated',
'size',
'related',
2018-02-22 12:08:11 +01:00
'',
2018-02-16 16:53:01 +01:00
];
const handleChangeSort = (name) => {
if (sort === name) {
changeSort(`-${name}`);
} else if (sort === `-${name}`) {
changeSort('hash');
} else if (name === 'updated' || name === 'related') {
changeSort('hash');
} else {
changeSort(name);
}
};
const shouldDisplaySort = (title) => sort === title && styles.icon || sort === `-${title}` && styles.iconDesc || '';
2018-02-16 16:53:01 +01:00
return (
<li className={styles.listheaderWrapper}>
<div className={cn(styles.listHeader)}>
2018-02-23 12:21:57 +01:00
<div>
<div />
<div className={shouldDisplaySort('type')} onClick={() => handleChangeSort('type')}>
2018-02-23 12:21:57 +01:00
<FormattedMessage id="upload.ListHeader.type" />
<span />
2018-02-23 12:21:57 +01:00
</div>
</div>
2018-02-16 16:53:01 +01:00
{titles.map((title, key) => {
if (title !== '') {
return (
<div key={key} className={shouldDisplaySort(title)} onClick={() => handleChangeSort(title)}>
2018-02-16 16:53:01 +01:00
<FormattedMessage id={`upload.ListHeader.${title}`} />
<span />
2018-02-16 16:53:01 +01:00
</div>
);
}
return <div key={key} />;
})}
</div>
</li>
);
}
ListHeader.defaultProps = {
changeSort: () => {},
};
ListHeader.propTypes = {
changeSort: PropTypes.func,
sort: PropTypes.string.isRequired,
};
2018-02-16 16:53:01 +01:00
export default ListHeader;