Add tracker filter an abstract components along the way

This commit is contained in:
John Furrow
2016-02-07 18:06:40 -08:00
parent 591eeed698
commit dc423ac6e9
26 changed files with 450 additions and 93 deletions
+17 -7
View File
@@ -1,14 +1,24 @@
import propsMaps from '../../../../shared/constants/propsMap';
export function filterTorrents(torrentList, filterBy) {
export function filterTorrents(torrentList, opts) {
let statusMap = propsMaps.clientStatus;
let {type, filter} = opts;
if (filterBy !== 'all') {
torrentList = torrentList.filter((torrent) => {
if (torrent.status.indexOf(statusMap[filterBy]) > -1) {
return torrent;
}
});
if (filter !== 'all') {
if (type === 'status') {
let statusFilter = statusMap[filter];
return torrentList.filter(function(torrent) {
if (torrent.status.indexOf(statusFilter) > -1) {
return torrent;
}
});
} else if (type === 'tracker') {
return torrentList.filter(function(torrent) {
if (torrent.trackers.indexOf(filter) > -1) {
return torrent;
}
});
}
}
return torrentList;