diff --git a/client/source/scripts/stores/TorrentStore.js b/client/source/scripts/stores/TorrentStore.js index 7a97ffac..b7ae7f9b 100644 --- a/client/source/scripts/stores/TorrentStore.js +++ b/client/source/scripts/stores/TorrentStore.js @@ -80,28 +80,28 @@ class TorrentStoreClass extends BaseStore { } setTorrents(torrents) { + let torrentsSort = TorrentFilterStore.getTorrentsSort(); + this.torrents = sortTorrents( Object.assign([], torrents), - TorrentFilterStore.getTorrentsSort() + {direction: torrentsSort.direction, property: torrentsSort.value} ); let statusFilter = TorrentFilterStore.getStatusFilter(); let searchFilter = TorrentFilterStore.getSearchFilter(); - if (statusFilter || searchFilter) { - let filteredTorrents = Object.assign([], this.torrents); + let filteredTorrents = Object.assign([], this.torrents); - if (statusFilter && statusFilter !== 'all') { - filteredTorrents = filterTorrents(filteredTorrents, statusFilter); - } - - if (searchFilter && searchFilter !== '') { - filteredTorrents = searchTorrents(filteredTorrents, searchFilter); - } - - this.filteredTorrents = filteredTorrents; + if (statusFilter && statusFilter !== 'all') { + filteredTorrents = filterTorrents(filteredTorrents, statusFilter); } + if (searchFilter && searchFilter !== '') { + filteredTorrents = searchTorrents(filteredTorrents, searchFilter); + } + + this.filteredTorrents = filteredTorrents; + this.emit(EventTypes.CLIENT_TORRENTS_REQUEST_SUCCESS); } diff --git a/client/source/scripts/util/sortTorrents.js b/client/source/scripts/util/sortTorrents.js index ce7087bf..8b63d790 100644 --- a/client/source/scripts/util/sortTorrents.js +++ b/client/source/scripts/util/sortTorrents.js @@ -2,9 +2,8 @@ export function sortTorrents(torrents, sortBy) { if (torrents.length) { let direction = sortBy.direction; let property = sortBy.property; - let sortedTorrents = Object.assign([], torrents); - sortedTorrents.sort(function(a, b) { + torrents.sort(function(a, b) { let valA = a[property]; let valB = b[property]; @@ -49,7 +48,7 @@ export function sortTorrents(torrents, sortBy) { return 0; }); - return sortedTorrents; + return torrents; } else { return torrents; }