Add context menu option to toggle Sort by Name

This commit is contained in:
David Ernst
2019-05-04 22:39:27 -07:00
parent 2dc2953831
commit 2466b2e0a6
2 changed files with 18 additions and 3 deletions

View File

@@ -279,6 +279,16 @@ module.exports = class TorrentListController {
enabled: torrentSummary.torrentFileName != null
}))
menu.append(new electron.remote.MenuItem({
type: 'separator'
}))
const sortedByName = this.state.saved.prefs.sortByName
menu.append(new electron.remote.MenuItem({
label: `${sortedByName ? '✓ ' : ''}Sort by Name`,
click: () => dispatch('updatePreferences', 'sortByName', !sortedByName)
}))
menu.popup(electron.remote.getCurrentWindow())
}

View File

@@ -279,12 +279,17 @@ module.exports = class TorrentList extends React.Component {
)
} else {
// We do know the files. List them and show download stats for each one
const sortByName = this.props.state.saved.prefs.sortByName
const sorter = natsort()
const fileRows = torrentSummary.files
let fileRows = torrentSummary.files
.filter((file) => !file.path.includes('/.____padding_file/'))
.map((file, index) => ({ file, index }))
.sort((a, b) => sorter(a.file.name, b.file.name))
.map((object) => this.renderFileRow(torrentSummary, object.file, object.index))
if (sortByName) {
fileRows = fileRows.sort((a, b) => sorter(a.file.name, b.file.name))
}
fileRows = fileRows.map((object) => this.renderFileRow(torrentSummary, object.file, object.index))
filesElement = (
<div key='files' className='files'>