Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove torrent immediately, but allow Undo #1788

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
14 changes: 7 additions & 7 deletions src/renderer/components/remove-torrent-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ const { dispatch, dispatcher } = require('../lib/dispatcher')
module.exports = class RemoveTorrentModal extends React.Component {
render () {
const state = this.props.state
const message = state.modal.deleteData
? 'Are you sure you want to remove this torrent from the list and delete the data file?'
: 'Are you sure you want to remove this torrent from the list?'
const buttonText = state.modal.deleteData ? 'REMOVE DATA' : 'REMOVE'

return (
<div>
<p><strong>{message}</strong></p>
<p>
<strong>
Are you sure you want to remove this torrent from the list and delete the data file?
</strong>
</p>
<ModalOKCancel
cancelText='CANCEL'
onCancel={dispatcher('exitModal')}
okText={buttonText}
okText='REMOVE DATA'
onOK={handleRemove}
/>
</div>
)

function handleRemove () {
dispatch('deleteTorrent', state.modal.infoHash, state.modal.deleteData)
dispatch('deleteTorrent', state.modal.infoHash, true)
dispatch('exitModal')
}
}
Expand Down
37 changes: 37 additions & 0 deletions src/renderer/components/remove-torrent-snackbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const React = require('react')

const Snackbar = require('material-ui/Snackbar').default

const { dispatch } = require('../lib/dispatcher')

module.exports = class RemoveTorrentSnackbar extends React.Component {
componentDidMount () {
dispatch('deleteTorrent', this.props.state.snackbar.infoHash)
}

render () {
const state = this.props.state

return (
<Snackbar
message='Torrent removed'
action='Undo'
autoHideDuration={5000}
onActionClick={handleUndo(state.snackbar.magnetURI)}
onRequestClose={clearSnackbar}
open
/>
)

function handleUndo (magnetURI) {
return function () {
dispatch('addTorrent', magnetURI)
dispatch('clearSnackbar')
}
}

function clearSnackbar () {
dispatch('clearSnackbar')
}
}
}
19 changes: 13 additions & 6 deletions src/renderer/controllers/torrent-list-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,18 @@ module.exports = class TorrentListController {
}
}

confirmDeleteTorrent (infoHash, deleteData) {
this.state.modal = {
id: 'remove-torrent-modal',
showDeleteTorrentSnackbar (infoHash, magnetURI) {
this.state.snackbar = {
id: 'remove-torrent-snackbar',
infoHash,
deleteData
magnetURI
}
}

confirmDeleteTorrentAndData (infoHash) {
this.state.modal = {
id: 'remove-torrent-data-modal',
infoHash
}
}

Expand Down Expand Up @@ -255,12 +262,12 @@ module.exports = class TorrentListController {

menu.append(new remote.MenuItem({
label: 'Remove From List',
click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, false)
click: () => dispatch('showDeleteTorrentSnackbar', torrentSummary.infoHash)
}))

menu.append(new remote.MenuItem({
label: 'Remove Data File',
click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, true)
click: () => dispatch('confirmDeleteTorrentAndData', torrentSummary.infoHash)
}))

menu.append(new remote.MenuItem({
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ const dispatchHandlers = {
resumeAllTorrents: () => controllers.torrentList().resumeAllTorrents(),
toggleTorrentFile: (infoHash, index) =>
controllers.torrentList().toggleTorrentFile(infoHash, index),
confirmDeleteTorrent: (infoHash, deleteData) =>
controllers.torrentList().confirmDeleteTorrent(infoHash, deleteData),
showDeleteTorrentSnackbar: (infoHash, magnetURI) =>
controllers.torrentList().showDeleteTorrentSnackbar(infoHash, magnetURI),
confirmDeleteTorrentAndData: (infoHash) =>
controllers.torrentList().confirmDeleteTorrentAndData(infoHash),
deleteTorrent: (infoHash, deleteData) =>
controllers.torrentList().deleteTorrent(infoHash, deleteData),
openTorrentListContextMenu: () => onPaste(),
Expand Down Expand Up @@ -323,6 +325,7 @@ const dispatchHandlers = {

// Navigation between screens (back, forward, ESC, etc)
exitModal: () => { state.modal = null },
clearSnackbar: () => { state.snackbar = null },
backToList,
escapeBack,
back: () => state.location.back(),
Expand Down
26 changes: 25 additions & 1 deletion src/renderer/pages/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ const Modals = {
'open-torrent-address-modal': createGetter(
() => require('../components/open-torrent-address-modal')
),
'remove-torrent-modal': createGetter(() => require('../components/remove-torrent-modal')),
'remove-torrent-data-modal': createGetter(() => require('../components/remove-torrent-modal')),
'update-available-modal': createGetter(() => require('../components/update-available-modal')),
'unsupported-media-modal': createGetter(() => require('../components/unsupported-media-modal')),
'delete-all-torrents-modal':
createGetter(() => require('../components/delete-all-torrents-modal'))
}

const SnackBars = {
'remove-torrent-snackbar': createGetter(() => require('../components/remove-torrent-snackbar'))
}

const fontFamily = process.platform === 'win32'
? '"Segoe UI", sans-serif'
: 'BlinkMacSystemFont, "Helvetica Neue", Helvetica, sans-serif'
Expand Down Expand Up @@ -75,6 +79,7 @@ class App extends React.Component {
{this.getErrorPopover()}
<div key='content' className='content'>{this.getView()}</div>
{this.getModal()}
{this.getSnackBar()}
</div>
</MuiThemeProvider>
)
Expand All @@ -98,6 +103,25 @@ class App extends React.Component {
)
}

getSnackBar () {
const state = this.props.state
if (!state.snackbar) return

if (!lightMuiTheme) {
const lightBaseTheme = require('material-ui/styles/baseThemes/lightBaseTheme').default
lightBaseTheme.fontFamily = fontFamily
lightBaseTheme.userAgent = false
lightMuiTheme = getMuiTheme(lightBaseTheme)
}

const SnackBarContents = SnackBars[state.snackbar.id]()
return (
<MuiThemeProvider muiTheme={lightMuiTheme}>
<SnackBarContents state={state} />
</MuiThemeProvider>
)
}

getModal () {
const state = this.props.state
if (!state.modal) return
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/pages/torrent-list-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ module.exports = class TorrentList extends React.Component {
key='delete-button'
className='icon delete'
title='Remove torrent'
onClick={dispatcher('confirmDeleteTorrent', infoHash, false)}
onClick={dispatcher('showDeleteTorrentSnackbar', infoHash, torrentSummary.magnetURI)}
>
close
</i>
Expand Down