import React from "react" import { DropdownButton, MenuItem } from "react-bootstrap" export default class TorrentsButton extends React.PureComponent { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); } handleClick(e, url) { e.preventDefault(); this.props.addTorrent(url); } render() { const entries = buildMenuItems(this.props.torrents); const searchUrl = `#/torrents/search/movies/${encodeURI(this.props.movieTitle)}`; return ( Advanced Search {entries.length > 0 && } {entries.map(function(e, index) { switch (e.type) { case "header": return ( {e.value} ); case "divider": return ( ); case "entry": return ( this.handleClick(event, e.url)}> {e.quality} ); } }, this)} ); } } function buildMenuItems(torrents) { if (!torrents) { return []; } const t = torrents.groupBy((el) => el.get("source")); // Build the array of entries let entries = []; let dividerCount = t.size - 1; for (let [source, torrentList] of t.entrySeq()) { // Push the title entries.push({ type: "header", value: source, }); // Push the torrents for (let torrent of torrentList) { entries.push({ type: "entry", quality: torrent.get("quality"), url: torrent.get("url"), }); } // Push the divider if (dividerCount > 0) { dividerCount--; entries.push({ type: "divider" }); } } return entries; }