2018-06-06 18:51:24 +02:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Search
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
2018-06-07 10:38:30 +02:00
|
|
|
import { upperFirst } from 'lodash';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2018-06-06 18:51:24 +02:00
|
|
|
|
2018-06-07 10:38:30 +02:00
|
|
|
import Logo from 'assets/images/icon_filter.png';
|
2018-06-06 18:51:24 +02:00
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
2018-06-07 10:38:30 +02:00
|
|
|
const WAIT = 100;
|
|
|
|
|
|
2018-06-06 18:51:24 +02:00
|
|
|
class Search extends React.Component {
|
|
|
|
|
state = { value: '' };
|
|
|
|
|
|
2018-06-07 10:38:30 +02:00
|
|
|
timer = null;
|
|
|
|
|
|
2018-06-06 18:51:24 +02:00
|
|
|
handleChange = ({ target }) => {
|
2018-06-07 10:38:30 +02:00
|
|
|
clearTimeout(this.timer);
|
2018-06-06 18:51:24 +02:00
|
|
|
this.setState({ value: target.value });
|
2018-06-07 10:38:30 +02:00
|
|
|
this.timer = setTimeout(this.triggerChange, WAIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO check if we send the request only when the user is done typing
|
|
|
|
|
triggerChange = () => {
|
|
|
|
|
console.log('End typing');
|
|
|
|
|
|
|
|
|
|
// this.props......
|
2018-06-06 18:51:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-06-07 10:38:30 +02:00
|
|
|
const { model } = this.props;
|
|
|
|
|
|
2018-06-06 18:51:24 +02:00
|
|
|
return (
|
|
|
|
|
<div className={styles.search}>
|
2018-06-07 10:38:30 +02:00
|
|
|
<div>
|
|
|
|
|
<FormattedMessage id="content-manager.components.Search.placeholder">
|
|
|
|
|
{(message) => (
|
|
|
|
|
<input
|
|
|
|
|
onChange={this.handleChange}
|
|
|
|
|
placeholder={message}
|
|
|
|
|
type="text"
|
|
|
|
|
value={this.state.value}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</FormattedMessage>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.searchLabel}>
|
|
|
|
|
<img src={Logo} alt="filter_logo" />
|
|
|
|
|
{upperFirst(model)}
|
|
|
|
|
</div>
|
2018-06-06 18:51:24 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 10:38:30 +02:00
|
|
|
Search.defaultProps = {
|
|
|
|
|
model: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Search.propTypes = {
|
|
|
|
|
model: PropTypes.string,
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-06 18:51:24 +02:00
|
|
|
export default Search;
|