Misc file moving and cleanup
- Rename JS/CSS for main.html to be consistent (main.js, main.css) - Add hx.js module to reduce virtual-dom boilerplate - Move state.js into renderer/lib.js where it belongs - Rename torrent-list.js -> home.js for consistency - Rename create-torrent-page.js -> create-torrent.js for consistency
This commit is contained in:
@@ -8,6 +8,7 @@ module.exports = {
|
||||
// () => dispatch(<args>)
|
||||
// ... this prevents virtual-dom from updating every listener on every update()
|
||||
var _dispatchers = {}
|
||||
|
||||
var _dispatch = () => {}
|
||||
|
||||
function setDispatch (dispatch) {
|
||||
@@ -17,14 +18,18 @@ function setDispatch (dispatch) {
|
||||
// Get a _memoized event handler that calls dispatch()
|
||||
// All args must be JSON-able
|
||||
function dispatcher (...args) {
|
||||
var json = JSON.stringify(args)
|
||||
var handler = _dispatchers[json]
|
||||
var str = JSON.stringify(args)
|
||||
var handler = _dispatchers[str]
|
||||
if (!handler) {
|
||||
handler = _dispatchers[json] = (e) => {
|
||||
// Don't click on whatever is below the button
|
||||
handler = _dispatchers[str] = function (e) {
|
||||
// Do not propagate click to elements below the button
|
||||
e.stopPropagation()
|
||||
// Don't regisiter clicks on disabled buttons
|
||||
if (e.currentTarget.classList.contains('disabled')) return
|
||||
|
||||
if (e.currentTarget.classList.contains('disabled')) {
|
||||
// Do not allow clicks on disabled buttons
|
||||
return
|
||||
}
|
||||
|
||||
_dispatch.apply(null, args)
|
||||
}
|
||||
}
|
||||
|
||||
5
renderer/lib/hx.js
Normal file
5
renderer/lib/hx.js
Normal file
@@ -0,0 +1,5 @@
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
module.exports = hx
|
||||
@@ -3,8 +3,8 @@ var path = require('path')
|
||||
|
||||
var remote = electron.remote
|
||||
|
||||
var config = require('../config')
|
||||
var LocationHistory = require('./lib/location-history')
|
||||
var config = require('../../config')
|
||||
var LocationHistory = require('./location-history')
|
||||
|
||||
module.exports = {
|
||||
getInitialState,
|
||||
@@ -280,36 +280,36 @@ table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.create-torrent-page {
|
||||
.create-torrent {
|
||||
padding: 10px 25px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.create-torrent-page .torrent-attribute {
|
||||
.create-torrent .torrent-attribute {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.create-torrent-page .torrent-attribute>* {
|
||||
.create-torrent .torrent-attribute>* {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.create-torrent-page .torrent-attribute label {
|
||||
.create-torrent .torrent-attribute label {
|
||||
width: 60px;
|
||||
margin-right: 10px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.create-torrent-page .torrent-attribute>div {
|
||||
.create-torrent .torrent-attribute>div {
|
||||
width: calc(100% - 90px);
|
||||
}
|
||||
|
||||
.create-torrent-page .torrent-attribute div {
|
||||
.create-torrent .torrent-attribute div {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.create-torrent-page .torrent-attribute textarea {
|
||||
.create-torrent .torrent-attribute textarea {
|
||||
width: calc(100% - 80px);
|
||||
height: 80px;
|
||||
color: #eee;
|
||||
@@ -321,11 +321,11 @@ table {
|
||||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
.create-torrent-page textarea.torrent-trackers {
|
||||
.create-torrent textarea.torrent-trackers {
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.create-torrent-page input.torrent-is-private {
|
||||
.create-torrent input.torrent-is-private {
|
||||
width: initial;
|
||||
margin: 0;
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="index.css" charset="utf-8">
|
||||
<link rel="stylesheet" href="main.css" charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script async src="index.js"></script>
|
||||
<script async src="main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -28,7 +28,7 @@ var App = require('./views/app')
|
||||
var config = require('../config')
|
||||
var errors = require('./lib/errors')
|
||||
var sound = require('./lib/sound')
|
||||
var State = require('./state')
|
||||
var State = require('./lib/state')
|
||||
var TorrentPlayer = require('./lib/torrent-player')
|
||||
var TorrentSummary = require('./lib/torrent-summary')
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
module.exports = App
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var hx = require('../lib/hx')
|
||||
var Header = require('./header')
|
||||
|
||||
var Views = {
|
||||
'home': require('./torrent-list'),
|
||||
'home': require('./home'),
|
||||
'player': require('./player'),
|
||||
'create-torrent': require('./create-torrent-page'),
|
||||
'create-torrent': require('./create-torrent'),
|
||||
'preferences': require('./preferences')
|
||||
}
|
||||
|
||||
var Modals = {
|
||||
'open-torrent-address-modal': require('./open-torrent-address-modal'),
|
||||
'update-available-modal': require('./update-available-modal'),
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
module.exports = CreateTorrentPage
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var createTorrent = require('create-torrent')
|
||||
var path = require('path')
|
||||
var prettyBytes = require('prettier-bytes')
|
||||
|
||||
var {dispatch, dispatcher} = require('../lib/dispatcher')
|
||||
var hx = require('../lib/hx')
|
||||
|
||||
function CreateTorrentPage (state) {
|
||||
var info = state.location.current()
|
||||
@@ -59,7 +56,7 @@ function CreateTorrentPage (state) {
|
||||
var collapsedClass = info.showAdvanced ? 'expanded' : 'collapsed'
|
||||
|
||||
return hx`
|
||||
<div class='create-torrent-page'>
|
||||
<div class='create-torrent'>
|
||||
<h2>Create torrent ${defaultName}</h2>
|
||||
<p class="torrent-info">
|
||||
${torrentInfo}
|
||||
@@ -132,7 +129,7 @@ function CreateTorrentPage (state) {
|
||||
|
||||
function CreateTorrentErrorPage () {
|
||||
return hx`
|
||||
<div class='create-torrent-page'>
|
||||
<div class='create-torrent'>
|
||||
<h2>Create torrent</h2>
|
||||
<p class="torrent-info">
|
||||
<p>
|
||||
@@ -1,10 +1,7 @@
|
||||
module.exports = Header
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var {dispatcher} = require('../lib/dispatcher')
|
||||
var hx = require('../lib/hx')
|
||||
|
||||
function Header (state) {
|
||||
return hx`
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
module.exports = TorrentList
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
var prettyBytes = require('prettier-bytes')
|
||||
|
||||
var hx = require('../lib/hx')
|
||||
var TorrentSummary = require('../lib/torrent-summary')
|
||||
var TorrentPlayer = require('../lib/torrent-player')
|
||||
var {dispatcher} = require('../lib/dispatcher')
|
||||
|
||||
function TorrentList (state) {
|
||||
var torrentRows = state.saved.torrents.map(
|
||||
(torrentSummary) => renderTorrent(torrentSummary))
|
||||
(torrentSummary) => renderTorrent(torrentSummary)
|
||||
)
|
||||
|
||||
return hx`
|
||||
<div class='torrent-list'>
|
||||
${torrentRows}
|
||||
@@ -20,11 +20,7 @@ function TorrentList (state) {
|
||||
</div>
|
||||
</div>`
|
||||
|
||||
// Renders a torrent in the torrent list
|
||||
// Includes name, download status, play button, background image
|
||||
// May be expanded for additional info, including the list of files inside
|
||||
function renderTorrent (torrentSummary) {
|
||||
// Get ephemeral data (like progress %) directly from the WebTorrent handle
|
||||
var infoHash = torrentSummary.infoHash
|
||||
var isSelected = infoHash && state.selectedInfoHash === infoHash
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
module.exports = OpenTorrentAddressModal
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var {dispatch} = require('../lib/dispatcher')
|
||||
var hx = require('../lib/hx')
|
||||
|
||||
function OpenTorrentAddressModal (state) {
|
||||
return hx`
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
module.exports = Player
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var Bitfield = require('bitfield')
|
||||
var prettyBytes = require('prettier-bytes')
|
||||
var zeroFill = require('zero-fill')
|
||||
|
||||
var hx = require('../lib/hx')
|
||||
var TorrentSummary = require('../lib/torrent-summary')
|
||||
var {dispatch, dispatcher} = require('../lib/dispatcher')
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
module.exports = Preferences
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
var hx = require('../lib/hx')
|
||||
var {dispatch} = require('../lib/dispatcher')
|
||||
|
||||
var remote = require('electron').remote
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
module.exports = UnsupportedMediaModal
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var electron = require('electron')
|
||||
|
||||
var {dispatch, dispatcher} = require('../lib/dispatcher')
|
||||
var hx = require('../lib/hx')
|
||||
|
||||
function UnsupportedMediaModal (state) {
|
||||
var err = state.modal.error
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
module.exports = UpdateAvailableModal
|
||||
|
||||
var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var electron = require('electron')
|
||||
|
||||
var {dispatch} = require('../lib/dispatcher')
|
||||
var hx = require('../lib/hx')
|
||||
|
||||
function UpdateAvailableModal (state) {
|
||||
return hx`
|
||||
|
||||
Reference in New Issue
Block a user