From 64892715d8d0445c1be8be383021303e1a38dc42 Mon Sep 17 00:00:00 2001 From: Raphael Ferreira Date: Mon, 28 Nov 2016 17:59:20 -0200 Subject: [PATCH 1/5] added remove-torrent-snackbar --- .../components/remove-torrent-snackbar.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/renderer/components/remove-torrent-snackbar.js diff --git a/src/renderer/components/remove-torrent-snackbar.js b/src/renderer/components/remove-torrent-snackbar.js new file mode 100644 index 0000000000..3fc56651da --- /dev/null +++ b/src/renderer/components/remove-torrent-snackbar.js @@ -0,0 +1,33 @@ +const React = require('react') + +const Snackbar = require('material-ui/Snackbar').default + +const {dispatch} = require('../lib/dispatcher') + +module.exports = class RemoveTorrentSnackbar extends React.Component { + render () { + const state = this.props.state + const message = state.snackbar.deleteData + ? 'Torrent and data file removed' + : 'Torrent removed' + + dispatch('deleteTorrent', state.snackbar.infoHash, false) + + return ( + + ) + + function handleUndo () { + dispath('addTorrent', state.snackbar.infoHash) + } + + function handleRemove () { + dispatch('deleteTorrent', state.snackbar.infoHash, state.snackbar.deleteData) + } + } +} From b53d68f14d3c1a43db7ca1e0611ee50dc9ffb72a Mon Sep 17 00:00:00 2001 From: Raphael Ferreira Date: Mon, 28 Nov 2016 17:59:55 -0200 Subject: [PATCH 2/5] torrent list controller should push a snackbar, instead of a modal --- src/renderer/controllers/torrent-list-controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/controllers/torrent-list-controller.js b/src/renderer/controllers/torrent-list-controller.js index aabf1522df..f1b4f7bdb8 100644 --- a/src/renderer/controllers/torrent-list-controller.js +++ b/src/renderer/controllers/torrent-list-controller.js @@ -160,8 +160,8 @@ module.exports = class TorrentListController { } confirmDeleteTorrent (infoHash, deleteData) { - this.state.modal = { - id: 'remove-torrent-modal', + this.state.snackbar = { + id: 'remove-torrent-snackbar', infoHash, deleteData } From 64afbef2faed2f3e3c49f5c7489c4baf2b14c40c Mon Sep 17 00:00:00 2001 From: Raphael Ferreira Date: Mon, 28 Nov 2016 18:00:58 -0200 Subject: [PATCH 3/5] app.js should renders snackbars like modals --- src/renderer/pages/app.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/renderer/pages/app.js b/src/renderer/pages/app.js index 5d9ec80745..bfa491a36f 100644 --- a/src/renderer/pages/app.js +++ b/src/renderer/pages/app.js @@ -27,6 +27,10 @@ const Modals = { 'unsupported-media-modal': createGetter(() => require('../components/unsupported-media-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' @@ -73,6 +77,7 @@ class App extends React.Component { {this.getErrorPopover()}
{this.getView()}
{this.getModal()} + {this.getSnackBar()} ) @@ -96,6 +101,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 From 8bf83ea522ea4d76055deadbe4fc169a6fbeb6ff Mon Sep 17 00:00:00 2001 From: Raphael Ferreira Date: Mon, 28 Nov 2016 18:09:19 -0200 Subject: [PATCH 4/5] standard fixes --- .../components/remove-torrent-snackbar.js | 16 ++++++++-------- src/renderer/pages/app.js | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/renderer/components/remove-torrent-snackbar.js b/src/renderer/components/remove-torrent-snackbar.js index 3fc56651da..cc95090c58 100644 --- a/src/renderer/components/remove-torrent-snackbar.js +++ b/src/renderer/components/remove-torrent-snackbar.js @@ -12,18 +12,18 @@ module.exports = class RemoveTorrentSnackbar extends React.Component { : 'Torrent removed' dispatch('deleteTorrent', state.snackbar.infoHash, false) - + let open = true return ( - + ) function handleUndo () { - dispath('addTorrent', state.snackbar.infoHash) + dispatch('addTorrent', state.snackbar.infoHash) } function handleRemove () { diff --git a/src/renderer/pages/app.js b/src/renderer/pages/app.js index bfa491a36f..c5accfbf69 100644 --- a/src/renderer/pages/app.js +++ b/src/renderer/pages/app.js @@ -103,7 +103,7 @@ class App extends React.Component { getSnackBar () { const state = this.props.state - if(!state.snackbar) return + if (!state.snackbar) return if (!lightMuiTheme) { const lightBaseTheme = require('material-ui/styles/baseThemes/lightBaseTheme').default From cff2f980e556afb927ad6dd86ba2f9046e65e992 Mon Sep 17 00:00:00 2001 From: David Ernst Date: Wed, 5 Feb 2020 16:45:47 -0800 Subject: [PATCH 5/5] Fix remove-torrent-snackbar, leave remove-torrent-and-data-modal --- .../components/remove-torrent-modal.js | 14 ++++---- .../components/remove-torrent-snackbar.js | 34 +++++++++++-------- .../controllers/torrent-list-controller.js | 15 +++++--- src/renderer/main.js | 7 ++-- src/renderer/pages/app.js | 2 +- src/renderer/pages/torrent-list-page.js | 2 +- 6 files changed, 44 insertions(+), 30 deletions(-) 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 index cc95090c58..fbe3415e93 100644 --- a/src/renderer/components/remove-torrent-snackbar.js +++ b/src/renderer/components/remove-torrent-snackbar.js @@ -2,32 +2,36 @@ const React = require('react') const Snackbar = require('material-ui/Snackbar').default -const {dispatch} = require('../lib/dispatcher') +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 - const message = state.snackbar.deleteData - ? 'Torrent and data file removed' - : 'Torrent removed' - dispatch('deleteTorrent', state.snackbar.infoHash, false) - let open = true return ( + message='Torrent removed' + action='Undo' + autoHideDuration={5000} + onActionClick={handleUndo(state.snackbar.magnetURI)} + onRequestClose={clearSnackbar} + open + /> ) - function handleUndo () { - dispatch('addTorrent', state.snackbar.infoHash) + function handleUndo (magnetURI) { + return function () { + dispatch('addTorrent', magnetURI) + dispatch('clearSnackbar') + } } - function handleRemove () { - dispatch('deleteTorrent', state.snackbar.infoHash, state.snackbar.deleteData) + function clearSnackbar () { + dispatch('clearSnackbar') } } } diff --git a/src/renderer/controllers/torrent-list-controller.js b/src/renderer/controllers/torrent-list-controller.js index 5f4537d6fe..1a981bb52d 100644 --- a/src/renderer/controllers/torrent-list-controller.js +++ b/src/renderer/controllers/torrent-list-controller.js @@ -193,11 +193,18 @@ module.exports = class TorrentListController { } } - confirmDeleteTorrent (infoHash, deleteData) { + showDeleteTorrentSnackbar (infoHash, magnetURI) { this.state.snackbar = { id: 'remove-torrent-snackbar', infoHash, - deleteData + magnetURI + } + } + + confirmDeleteTorrentAndData (infoHash) { + this.state.modal = { + id: 'remove-torrent-data-modal', + infoHash } } @@ -253,12 +260,12 @@ module.exports = class TorrentListController { menu.append(new electron.remote.MenuItem({ label: 'Remove From List', - click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, false) + click: () => dispatch('showDeleteTorrentSnackbar', torrentSummary.infoHash) })) menu.append(new electron.remote.MenuItem({ label: 'Remove Data File', - click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, true) + click: () => dispatch('confirmDeleteTorrentAndData', torrentSummary.infoHash) })) menu.append(new electron.remote.MenuItem({ diff --git a/src/renderer/main.js b/src/renderer/main.js index be363d6c1e..2aac9d9945 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -251,8 +251,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), confirmDeleteAllTorrents: (deleteData) => @@ -322,6 +324,7 @@ const dispatchHandlers = { // Navigation between screens (back, forward, ESC, etc) exitModal: () => { state.modal = null }, + clearSnackbar: () => { state.snackbar = null }, backToList: backToList, escapeBack: escapeBack, back: () => state.location.back(), diff --git a/src/renderer/pages/app.js b/src/renderer/pages/app.js index d08dc3f114..109cd006a8 100644 --- a/src/renderer/pages/app.js +++ b/src/renderer/pages/app.js @@ -22,7 +22,7 @@ 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': diff --git a/src/renderer/pages/torrent-list-page.js b/src/renderer/pages/torrent-list-page.js index 286e9acf11..ea65208182 100644 --- a/src/renderer/pages/torrent-list-page.js +++ b/src/renderer/pages/torrent-list-page.js @@ -251,7 +251,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