From fc9a73d67f76c5884f678374e305c32f40e32ece Mon Sep 17 00:00:00 2001 From: Sergey Bargamon Date: Mon, 23 May 2016 10:43:55 +0300 Subject: [PATCH] #242 add sort by file name --- renderer/views/torrent-list.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/renderer/views/torrent-list.js b/renderer/views/torrent-list.js index ce63d616..d8e0c7b1 100644 --- a/renderer/views/torrent-list.js +++ b/renderer/views/torrent-list.js @@ -186,8 +186,8 @@ function TorrentList (state) { filesElement = hx`
${message}
` } else { // We do know the files. List them and show download stats for each one - var fileRows = torrentSummary.files.map( - (file, index) => renderFileRow(torrentSummary, file, index)) + var fileRows = torrentSummary.files.sort(fileSortHelper).map( + (file, index) => renderFileRow(torrentSummary, file, index)) filesElement = hx`
Files @@ -205,6 +205,15 @@ function TorrentList (state) { ` } + function fileSortHelper (a, b) { + var result = 0 + if (a.name > b.name) { + result = 1 + } else if (a.name < b.name) { + result = -1 + } + return result + } // Show a single torrentSummary file in the details view for a single torrent function renderFileRow (torrentSummary, file, index) { // First, find out how much of the file we've downloaded