93 lines
2.3 KiB
JavaScript
93 lines
2.3 KiB
JavaScript
import React from "react"
|
|
import PropTypes from "prop-types"
|
|
import { List } from "immutable"
|
|
|
|
import Dropdown from "react-bootstrap/Dropdown"
|
|
|
|
function buildMenuItems(torrents) {
|
|
if (!torrents || torrents.size === 0) {
|
|
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;
|
|
}
|
|
|
|
const TorrentsButton = (props) => {
|
|
const entries = buildMenuItems(props.torrents);
|
|
const searchUrl = `#/torrents/search/movies/${encodeURI(props.movieTitle)}`;
|
|
return (
|
|
<Dropdown drop="up">
|
|
<Dropdown.Toggle variant="secondary" id="movie-torrents">
|
|
Torrents
|
|
</Dropdown.Toggle>
|
|
|
|
<Dropdown.Menu>
|
|
<Dropdown.Header>
|
|
<span className="text-warning">Advanced</span>
|
|
</Dropdown.Header>
|
|
<Dropdown.Item href={searchUrl} >
|
|
<i className="fa fa-search" aria-hidden="true"></i> Search
|
|
</Dropdown.Item>
|
|
{entries.length > 0 &&
|
|
<Dropdown.Divider />
|
|
}
|
|
{entries.map((e, index) => {
|
|
switch (e.type) {
|
|
case "header":
|
|
return (
|
|
<Dropdown.Header key={index}>
|
|
<span className="text-warning">{e.value}</span>
|
|
</Dropdown.Header>
|
|
);
|
|
case "divider":
|
|
return (
|
|
<Dropdown.Divider key={index}/>
|
|
);
|
|
case "entry":
|
|
return (
|
|
<Dropdown.Item key={index} onClick={() => props.addTorrent(e.url)}>
|
|
{e.quality}
|
|
</Dropdown.Item>
|
|
);
|
|
}
|
|
})}
|
|
</Dropdown.Menu>
|
|
</Dropdown>
|
|
);
|
|
}
|
|
TorrentsButton.propTypes = {
|
|
torrents: PropTypes.instanceOf(List),
|
|
addTorrent: PropTypes.func.isRequired,
|
|
movieTitle: PropTypes.string.isRequired,
|
|
}
|
|
|
|
export default TorrentsButton;
|