Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Use href instead of onClick (allows right click -> open in new window)
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Nov 15, 2016
1 parent ea6f8fe commit e896f82
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 32 deletions.
1 change: 1 addition & 0 deletions app/extensions/torrent/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ downloadingTorrent=Downloading Torrent
files=Files
num=#
torrentStatus=Torrent Status
backToTorrent=Back to Torrent
8 changes: 3 additions & 5 deletions js/components/sortableTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,10 @@ class SortableTable extends React.Component {
if (dataType === 'object' && firstEntry.value) {
dataType = typeof firstEntry.value
}
const headerClasses = {
return <th className={cx({
'sort-header': true,
'sort-default': this.sortingDisabled || heading === this.props.defaultHeading
}
headerClasses['heading-' + heading] = true
return <th className={cx(headerClasses)}
'sort-default': this.sortingDisabled || heading === this.props.defaultHeading,
[`heading-${heading}`]: true})}
data-sort-method={dataType === 'number' ? 'number' : undefined}
data-sort-order={this.props.defaultHeadingSortOrder}>
{
Expand Down
8 changes: 6 additions & 2 deletions js/webtorrent/components/mediaViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ const React = require('react')

class MediaViewer extends React.Component {
render () {
const torrent = this.props.torrent
const {torrent} = this.props
const ix = this.props.ix

let content
if (torrent.serverURL != null) {
content = <iframe src={torrent.serverURL + '/' + ix} sandbox='allow-same-origin allow-scripts' />
content = (
<iframe
src={torrent.serverURL + '/' + ix}
sandbox='allow-same-origin allow-scripts' />
)
} else {
content = <div>Loading...</div>
}
Expand Down
32 changes: 20 additions & 12 deletions js/webtorrent/components/torrentFileList.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const parseTorrent = require('parse-torrent')
const prettierBytes = require('prettier-bytes')
const React = require('react')

const SortableTable = require('../../components/sortableTable')

class TorrentFileList extends React.Component {
constructor () {
super()
this.onClick = this.onClick.bind(this)
}

onClick (file) {
window.location = this.props.torrentID + '&ix=' + this.props.files.indexOf(file)
// Return the torrentID of a particular file, by index
getFileHref (index) {
// const index = this.props.files.indexOf(file)
const parsedTorrent = Object.assign({}, this.props.parsedTorrent, {ix: index})
return parseTorrent.toMagnetURI(parsedTorrent)
}

render () {
Expand All @@ -28,15 +28,23 @@ class TorrentFileList extends React.Component {
defaultHeading='num'
defaultHeadingSortOrder='asc'
rows={files.map((file, i) => [
String(i + 1),
file.name,
prettierBytes(file.length)
{
cell: <a href={this.getFileHref(i)}>{i + 1}</a>,
value: i + 1
},
{
cell: <a href={this.getFileHref(i)}>{file.name}</a>,
value: file.name
},
{
cell: <a href={this.getFileHref(i)}>{prettierBytes(file.length)}</a>,
value: file.length
}
])}
rowObjects={files}
columnClassNames={['num', 'name', 'size']}
addHoverClass
stateOwner={this.props.stateOwner}
onClick={this.onClick} />
stateOwner={this.props.stateOwner} />
]
}

Expand Down
6 changes: 3 additions & 3 deletions js/webtorrent/components/torrentViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TorrentViewer extends React.Component {
}

render () {
const {torrent, torrentID, errorMessage, dispatch} = this.props
const {torrent, parsedTorrent, errorMessage, dispatch} = this.props

let titleElem, mainButtonId
if (torrent) {
Expand Down Expand Up @@ -55,9 +55,9 @@ class TorrentViewer extends React.Component {
<div className='siteDetailsPageContent'>
<TorrentStatus torrent={torrent} errorMessage={errorMessage} />
<TorrentFileList
parsedTorrent={parsedTorrent}
files={torrent && torrent.files}
stateOwner={this}
torrentID={torrentID} />
stateOwner={this} />
{legalNotice}
</div>
</div>
Expand Down
15 changes: 6 additions & 9 deletions js/webtorrent/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,16 @@ class App extends React.Component {
this.dispatch = this.dispatch.bind(this)
}

dispatch (action) {
dispatch (action, ...args) {
switch (action) {
case 'start':
return start()
case 'saveTorrentFile':
return saveTorrentFile()
default:
console.error('Ignoring unknown dispatch type: ' + JSON.stringify(action))
case 'start': return start(...args)
case 'saveTorrentFile': return saveTorrentFile(...args)
default: console.error('Ignoring unknown dispatch type: ' + action)
}
}

render () {
const {torrent, torrentID, errorMessage, parsedTorrent} = state
const {torrent, errorMessage, parsedTorrent} = state
const ix = parsedTorrent && parsedTorrent.ix // Selected file index
let name = parsedTorrent && parsedTorrent.name
if (!name) {
Expand All @@ -135,7 +132,7 @@ class App extends React.Component {
<TorrentViewer
name={name}
torrent={torrent}
torrentID={torrentID}
parsedTorrent={parsedTorrent}
errorMessage={errorMessage}
dispatch={this.dispatch} />
)
Expand Down
13 changes: 12 additions & 1 deletion less/webtorrent.less
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
-webkit-user-select: none;
table-layout: fixed;

td {
a {
display: block;
width: 100%;
height: 100%;
padding-left: 5px;
padding-right: 5px;
text-decoration: none;
}

.num {
Expand Down Expand Up @@ -117,3 +121,10 @@ iframe {
margin-top: 20px;
margin-bottom: 20px;
}

.backToTorrent {
position: absolute;
top: 30px;
left: 30px;
z-index: 1000;
}

0 comments on commit e896f82

Please sign in to comment.