отображение результатов поиска

This commit is contained in:
Alexey Kasyanchuk
2017-01-01 06:40:51 +03:00
parent 1b6a15bcdd
commit 2b861167cd
2 changed files with 37 additions and 11 deletions

23
src/search-results.js Normal file
View File

@ -0,0 +1,23 @@
import React, { Component } from 'react';
export default class SearchResults extends Component {
render() {
return (
<div className="column">
{
this.props.results && this.props.results.length > 0
?
this.props.results.map((torrent, index) => {
return (
<div key={index}>
{torrent.name}
</div>
);
})
:
null
}
</div>
);
}
}

View File

@ -1,19 +1,22 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
export default class Search extends Component { import SearchResults from './search-results'
componentDidMount() {
} export default class Search extends Component {
render() { render() {
return ( return (
<div className="row"> <div className="column">
<input type='text' ref='searchInput' onKeyPress={(e) => { <div className='row'>
if (e.key === 'Enter') { <input type='text' ref='searchInput' onKeyPress={(e) => {
window.torrentSocket.emit('search', e.target.value, (torrents) => { if (e.key === 'Enter') {
console.log(torrents); window.torrentSocket.emit('search', e.target.value, (torrents) => {
}); this.searchData = torrents;
} this.forceUpdate();
}} /> });
}
}} />
</div>
<SearchResults results={this.searchData} />
</div> </div>
); );
} }