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

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