Merge pull request #47 from KevinMidboe/client_search-the-bay

Client search the bay
This commit is contained in:
2017-10-21 15:38:31 +02:00
committed by GitHub
3 changed files with 66 additions and 1 deletions

View File

@@ -67,7 +67,10 @@ class AdminComponent extends React.Component {
style={adminComponentStyle.sidebar} />
</div>
<div style={adminComponentStyle.selectedObjectPanel}>
<AdminRequestInfo selectedRequest={selectedRequest} />
<AdminRequestInfo
selectedRequest={selectedRequest}
listItemSelected={listItemSelected}
/>
</div>
</div>
)

View File

@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import PirateSearch from './PirateSearch.jsx'
class AdminRequestInfo extends Component {
@@ -54,6 +55,10 @@ class AdminRequestInfo extends Component {
<span>user_agent: {this.userAgent(request.user_agent)}</span><br />
<span>request_date: {request.requested_date}</span><br />
</div>
<PirateSearch
name={request.name} />
</div>
)
}

View File

@@ -0,0 +1,57 @@
import React, { Component } from 'react';
import { fetchJSON } from '../http.jsx';
class PirateSearch extends Component {
constructor() {
super();
this.state = {
response: [],
name: '',
}
}
sendToDownload(torrent) {
console.log(torrent.magnet)
let data = {magnet: torrent.magnet}
fetchJSON('https://apollo.kevinmidboe.com/api/v1/pirate/add', 'POST', data)
.then((response) => {
console.log(response)
})
}
searchTheBay() {
const query = this.props.name;
const type = this.props.type;
fetchJSON('https://apollo.kevinmidboe.com/api/v1/pirate/search?query='+query+'&type='+type, 'GET')
.then((response) => {
console.log(response.torrents)
this.setState({
response: response.torrents.map((torrent, index) => {
return (
<div key={index}>
<span>{torrent.name}</span><br />
<span>{torrent.size}</span><br />
<span>{torrent.seed}</span><br />
<button onClick={() => {this.sendToDownload(torrent)}}>Send to download</button>
<br /><br />
</div>
)
})
})
})
}
render() {
return (
<div>
<span>{this.props.name}</span>
<button onClick={() => {this.searchTheBay(this)}}>Load shit</button>
<span>{this.state.response}</span>
</div>
)
}
}
export default PirateSearch