import React from "react" import { connect } from "react-redux" import { bindActionCreators } from "redux" import { addTorrent, searchTorrents } from "../../actions/torrents" import Loader from "../loader/loader" import { OverlayTrigger, Tooltip } from "react-bootstrap" function mapStateToProps(state) { return { searching: state.torrentStore.get("searching"), results: state.torrentStore.get("searchResults"), }; } const mapDispatchToProps = (dispatch) => bindActionCreators({ addTorrent, searchTorrents }, dispatch) class TorrentSearch extends React.PureComponent { constructor(props) { super(props); this.handleSearchInput = this.handleSearchInput.bind(this); this.state = { search: (this.props.router.params.search || "") }; } handleSearchInput() { this.setState({ search: this.refs.search.value }); } handleClick(type) { if (this.state.search === "") { return } const url = `/torrents/search/${type}/${encodeURI(this.state.search)}`; this.props.router.push(url); } render() { const searchFromURL = this.props.router.params.search || ""; const typeFromURL = this.props.router.params.type || ""; return (
e.preventDefault()}>
this.handleClick("movies")} /> this.handleClick("shows")} />

); } } function SearchButton(props) { const color = (props.type === props.typeFromURL) ? "primary" : "default"; return (
); } function TorrentList(props) { if (props.searching) { return (); } if (props.searchFromURL === "") { return null; } if (props.results.size === 0) { return (

No results

); } return (
{props.results.map(function(el, index) { return ( ); })}
); } function Torrent(props) { return (

{props.data.get("name")}

props.addTorrent(props.data.get("url"))}>

{props.data.get("quality")} {props.data.get("source")} {props.data.get("upload_user")}
); } function TorrentHealth(props) { const seeders = props.seeders || 0; const leechers = props.leechers || 1; let color; let health; let ratio = seeders/leechers; if (seeders > 20) { health = "good"; color = "success"; } else { if (ratio > 1) { health = "medium"; color = "warning"; } else { health = "bad"; color = "danger"; } } const className = `text text-${color}`; const tooltip = (

Health: {health}

Seeders: {seeders}

Leechers: {props.leechers}

); return ( ); } export default connect(mapStateToProps, mapDispatchToProps)(TorrentSearch);