refactor torrent-list-controller
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
const React = require('react')
|
const React = require('react')
|
||||||
|
|
||||||
const ModalOKCancel = require('./modal-ok-cancel')
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
const {dispatch, dispatcher} = require('../lib/dispatcher')
|
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
||||||
|
|
||||||
module.exports = class DeleteAllTorrentsModal extends React.Component {
|
module.exports = class DeleteAllTorrentsModal extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const {state: {modal: {deleteData}}} = this.props
|
const { state: { modal: { deleteData } } } = this.props
|
||||||
const message = deleteData
|
const message = deleteData
|
||||||
? 'Are you sure you want to remove all the torrents from the list and delete the data files?'
|
? 'Are you sure you want to remove all the torrents from the list and delete the data files?'
|
||||||
: 'Are you sure you want to remove all the torrents from the list?'
|
: 'Are you sure you want to remove all the torrents from the list?'
|
||||||
|
|||||||
@@ -210,44 +210,29 @@ module.exports = class TorrentListController {
|
|||||||
|
|
||||||
// TODO: use torrentKey, not infoHash
|
// TODO: use torrentKey, not infoHash
|
||||||
deleteTorrent (infoHash, deleteData) {
|
deleteTorrent (infoHash, deleteData) {
|
||||||
ipcRenderer.send('wt-stop-torrenting', infoHash)
|
|
||||||
|
|
||||||
const index = this.state.saved.torrents.findIndex((x) => x.infoHash === infoHash)
|
const index = this.state.saved.torrents.findIndex((x) => x.infoHash === infoHash)
|
||||||
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
const summary = this.state.saved.torrents[index]
|
const summary = this.state.saved.torrents[index]
|
||||||
|
deleteTorrentFile(summary, deleteData)
|
||||||
// remove torrent and poster file
|
|
||||||
deleteFile(TorrentSummary.getTorrentPath(summary))
|
|
||||||
deleteFile(TorrentSummary.getPosterPath(summary))
|
|
||||||
|
|
||||||
// optionally delete the torrent data
|
|
||||||
if (deleteData) moveItemToTrash(summary)
|
|
||||||
|
|
||||||
// remove torrent from saved list
|
// remove torrent from saved list
|
||||||
this.state.saved.torrents.splice(index, 1)
|
this.state.saved.torrents.splice(index, 1)
|
||||||
dispatch('stateSave')
|
dispatch('stateSave')
|
||||||
}
|
|
||||||
|
|
||||||
// prevent user from going forward to a deleted torrent
|
// prevent user from going forward to a deleted torrent
|
||||||
this.state.location.clearForward('player')
|
this.state.location.clearForward('player')
|
||||||
sound.play('DELETE')
|
sound.play('DELETE')
|
||||||
|
} else {
|
||||||
|
throw new TorrentKeyNotFoundError(infoHash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteAllTorrents (deleteData) {
|
deleteAllTorrents (deleteData) {
|
||||||
this.state.saved.torrents.forEach((summary) => {
|
this.state.saved.torrents.forEach((summary) => deleteTorrentFile(summary, deleteData))
|
||||||
ipcRenderer.send('wt-stop-torrenting', summary.infoHash)
|
|
||||||
|
|
||||||
// remove torrent and poster file
|
|
||||||
deleteFile(TorrentSummary.getTorrentPath(summary))
|
|
||||||
deleteFile(TorrentSummary.getPosterPath(summary))
|
|
||||||
|
|
||||||
if (deleteData) moveItemToTrash(summary)
|
|
||||||
|
|
||||||
dispatch('stateSave')
|
|
||||||
})
|
|
||||||
|
|
||||||
this.state.saved.torrents = []
|
this.state.saved.torrents = []
|
||||||
|
dispatch('stateSave')
|
||||||
|
|
||||||
// prevent user from going forward to a deleted torrent
|
// prevent user from going forward to a deleted torrent
|
||||||
this.state.location.clearForward('player')
|
this.state.location.clearForward('player')
|
||||||
@@ -313,7 +298,7 @@ module.exports = class TorrentListController {
|
|||||||
// Shows a Save File dialog, then saves the .torrent file wherever the user requests
|
// Shows a Save File dialog, then saves the .torrent file wherever the user requests
|
||||||
saveTorrentFileAs (torrentKey) {
|
saveTorrentFileAs (torrentKey) {
|
||||||
const torrentSummary = TorrentSummary.getByKey(this.state, torrentKey)
|
const torrentSummary = TorrentSummary.getByKey(this.state, torrentKey)
|
||||||
if (!torrentSummary) throw new Error('Missing torrentKey: ' + torrentKey)
|
if (!torrentSummary) throw new TorrentKeyNotFoundError(torrentKey)
|
||||||
const downloadPath = this.state.saved.prefs.downloadPath
|
const downloadPath = this.state.saved.prefs.downloadPath
|
||||||
const newFileName = path.parse(torrentSummary.name).name + '.torrent'
|
const newFileName = path.parse(torrentSummary.name).name + '.torrent'
|
||||||
const win = electron.remote.getCurrentWindow()
|
const win = electron.remote.getCurrentWindow()
|
||||||
@@ -398,3 +383,14 @@ function moveItemToTrash (torrentSummary) {
|
|||||||
function showItemInFolder (torrentSummary) {
|
function showItemInFolder (torrentSummary) {
|
||||||
ipcRenderer.send('showItemInFolder', TorrentSummary.getFileOrFolder(torrentSummary))
|
ipcRenderer.send('showItemInFolder', TorrentSummary.getFileOrFolder(torrentSummary))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteTorrentFile (torrentSummary, deleteData) {
|
||||||
|
ipcRenderer.send('wt-stop-torrenting', torrentSummary.infoHash)
|
||||||
|
|
||||||
|
// remove torrent and poster file
|
||||||
|
deleteFile(TorrentSummary.getTorrentPath(torrentSummary))
|
||||||
|
deleteFile(TorrentSummary.getPosterPath(torrentSummary))
|
||||||
|
|
||||||
|
// optionally delete the torrent data
|
||||||
|
if (deleteData) moveItemToTrash(torrentSummary)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user