dispatch/client/js/components/pages/Chat/Search.js

39 lines
866 B
JavaScript
Raw Normal View History

import React, { memo, useRef, useEffect } from 'react';
2016-01-22 23:41:35 +00:00
import SearchResult from './SearchResult';
2015-12-28 23:34:32 +00:00
const Search = ({ search, onSearch }) => {
const inputEl = useRef();
2015-12-28 23:34:32 +00:00
2019-01-30 02:51:13 +00:00
useEffect(() => {
if (search.show) {
inputEl.current.focus();
}
}, [search.show]);
2015-12-28 23:34:32 +00:00
const style = {
display: search.show ? 'block' : 'none'
};
2015-12-28 23:34:32 +00:00
let i = 0;
const results = search.results.map(result => (
<SearchResult key={i++} result={result} />
));
2016-01-05 18:29:22 +00:00
return (
<div className="search" style={style}>
<div className="search-input-wrap">
<i className="icon-search" />
<input
ref={inputEl}
className="search-input"
type="text"
onChange={e => onSearch(e.target.value)}
/>
2015-12-28 23:34:32 +00:00
</div>
<div className="search-results">{results}</div>
</div>
);
};
export default memo(Search);