From 1668c4c614fd9534fbb547953fe0938ceeafd766 Mon Sep 17 00:00:00 2001
From: DC
Date: Fri, 8 Jul 2016 11:57:01 -0700
Subject: [PATCH] Refactor main.js: fix Create Torrent modal
---
renderer/controllers/torrent-list-controller.js | 7 +++++++
renderer/main.js | 1 +
renderer/views/create-torrent.js | 16 +++-------------
3 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/renderer/controllers/torrent-list-controller.js b/renderer/controllers/torrent-list-controller.js
index 29727052..2b4a7b36 100644
--- a/renderer/controllers/torrent-list-controller.js
+++ b/renderer/controllers/torrent-list-controller.js
@@ -55,6 +55,13 @@ module.exports = class TorrentListController {
findFilesRecursive(files, (allFiles) => this.showCreateTorrent(allFiles))
}
+ // Switches between the advanced and simple Create Torrent UI
+ toggleCreateTorrentAdvanced () {
+ var info = this.state.location.current()
+ if (info.url !== 'create-torrent') return
+ info.showAdvanced = !info.showAdvanced
+ }
+
// Creates a new torrent and start seeeding
createTorrent (options) {
var state = this.state
diff --git a/renderer/main.js b/renderer/main.js
index 3e3356ca..b94c9875 100644
--- a/renderer/main.js
+++ b/renderer/main.js
@@ -174,6 +174,7 @@ const dispatchHandlers = {
'addTorrent': (torrentId) => controllers.torrentList.addTorrent(torrentId),
'showCreateTorrent': (paths) => controllers.torrentList.showCreateTorrent(paths),
+ 'toggleCreateTorrentAdvanced': () => controllers.torrentList.toggleCreateTorrentAdvanced(),
'createTorrent': (options) => controllers.torrentList.createTorrent(options),
'toggleTorrent': (infoHash) => controllers.torrentList.toggleTorrent(infoHash),
'toggleTorrentFile': (infoHash, index) => controllers.torrentList.toggleTorrentFile(infoHash, index),
diff --git a/renderer/views/create-torrent.js b/renderer/views/create-torrent.js
index 28c8f5fd..42585431 100644
--- a/renderer/views/create-torrent.js
+++ b/renderer/views/create-torrent.js
@@ -65,7 +65,8 @@ function CreateTorrentPage (state) {
Path:
${pathPrefix}
-
+
${info.showAdvanced ? 'Basic' : 'Advanced'}
@@ -87,7 +88,7 @@ function CreateTorrentPage (state) {
- Cancel
+ Cancel
Create Torrent
@@ -114,17 +115,6 @@ function CreateTorrentPage (state) {
}
dispatch('createTorrent', options)
}
-
- function handleCancel () {
- dispatch('back')
- }
-
- function handleToggleShowAdvanced () {
- // TODO: what's the clean way to handle this?
- // Should every button on every screen have its own dispatch()?
- info.showAdvanced = !info.showAdvanced
- dispatch('update')
- }
}
function CreateTorrentErrorPage () {