diff --git a/src/renderer/components/remove-torrent-modal.js b/src/renderer/components/remove-torrent-modal.js index 4913f59d99..676557a3b3 100644 --- a/src/renderer/components/remove-torrent-modal.js +++ b/src/renderer/components/remove-torrent-modal.js @@ -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 (
-

{message}

+

+ + Are you sure you want to remove this torrent from the list and delete the data file? + +

) function handleRemove () { - dispatch('deleteTorrent', state.modal.infoHash, state.modal.deleteData) + dispatch('deleteTorrent', state.modal.infoHash, true) dispatch('exitModal') } } diff --git a/src/renderer/components/remove-torrent-snackbar.js b/src/renderer/components/remove-torrent-snackbar.js new file mode 100644 index 0000000000..fbe3415e93 --- /dev/null +++ b/src/renderer/components/remove-torrent-snackbar.js @@ -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 ( + + ) + + function handleUndo (magnetURI) { + return function () { + dispatch('addTorrent', magnetURI) + dispatch('clearSnackbar') + } + } + + function clearSnackbar () { + dispatch('clearSnackbar') + } + } +} diff --git a/src/renderer/controllers/torrent-list-controller.js b/src/renderer/controllers/torrent-list-controller.js index 158841a501..cf638a0e54 100644 --- a/src/renderer/controllers/torrent-list-controller.js +++ b/src/renderer/controllers/torrent-list-controller.js @@ -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 } } @@ -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({ diff --git a/src/renderer/main.js b/src/renderer/main.js index 945842eafb..c1e3355846 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -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(), @@ -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(), diff --git a/src/renderer/pages/app.js b/src/renderer/pages/app.js index d07bc3d19e..35bad12602 100644 --- a/src/renderer/pages/app.js +++ b/src/renderer/pages/app.js @@ -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' @@ -75,6 +79,7 @@ class App extends React.Component { {this.getErrorPopover()}
{this.getView()}
{this.getModal()} + {this.getSnackBar()} ) @@ -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 ( + + + + ) + } + getModal () { const state = this.props.state if (!state.modal) return diff --git a/src/renderer/pages/torrent-list-page.js b/src/renderer/pages/torrent-list-page.js index 1a52897d99..4f0b7edbe8 100644 --- a/src/renderer/pages/torrent-list-page.js +++ b/src/renderer/pages/torrent-list-page.js @@ -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