We can now sort filesizes that have a human size name and not in bytes. These values will be converted and saved as byte size.
This commit is contained in:
@@ -38,7 +38,8 @@ class TorrentTable extends Component {
|
|||||||
// Link to repo: https://github.com/sindresorhus/pretty-bytes
|
// Link to repo: https://github.com/sindresorhus/pretty-bytes
|
||||||
convertSizeToHumanSize(num) {
|
convertSizeToHumanSize(num) {
|
||||||
if (!Number.isFinite(num)) {
|
if (!Number.isFinite(num)) {
|
||||||
throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);
|
return num
|
||||||
|
// throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);
|
||||||
}
|
}
|
||||||
const neg = num < 0;
|
const neg = num < 0;
|
||||||
|
|
||||||
@@ -57,6 +58,17 @@ class TorrentTable extends Component {
|
|||||||
return (neg ? '-' : '') + numStr + ' ' + unit;
|
return (neg ? '-' : '') + numStr + ' ' + unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertHumanSizeToBytes(string) {
|
||||||
|
const [numStr, unit] = string.split(' ');
|
||||||
|
if (this.UNITS.indexOf(unit) === -1) {
|
||||||
|
return string
|
||||||
|
}
|
||||||
|
|
||||||
|
const exponent = this.UNITS.indexOf(unit) * 3
|
||||||
|
|
||||||
|
return numStr * (Math.pow(10, exponent))
|
||||||
|
}
|
||||||
|
|
||||||
sendToDownload(magnet) {
|
sendToDownload(magnet) {
|
||||||
const apiData = {
|
const apiData = {
|
||||||
magnet: magnet,
|
magnet: magnet,
|
||||||
@@ -80,8 +92,6 @@ class TorrentTable extends Component {
|
|||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(filteredByQuery)
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
torrentResponse: filteredByQuery,
|
torrentResponse: filteredByQuery,
|
||||||
filterQuery: query,
|
filterQuery: query,
|
||||||
@@ -101,6 +111,9 @@ class TorrentTable extends Component {
|
|||||||
let valueA = isNaN(a[col]) ? a[col] : parseInt(a[col])
|
let valueA = isNaN(a[col]) ? a[col] : parseInt(a[col])
|
||||||
let valueB = isNaN(b[col]) ? b[col] : parseInt(b[col])
|
let valueB = isNaN(b[col]) ? b[col] : parseInt(b[col])
|
||||||
|
|
||||||
|
valueA = (col == 'size') ? this.convertHumanSizeToBytes(valueA) : valueA
|
||||||
|
valueB = (col == 'size') ? this.convertHumanSizeToBytes(valueB) : valueB
|
||||||
|
|
||||||
if (direction)
|
if (direction)
|
||||||
return valueA<valueB? 1:valueA>valueB?-1:0;
|
return valueA<valueB? 1:valueA>valueB?-1:0;
|
||||||
else
|
else
|
||||||
@@ -193,4 +206,4 @@ class TorrentTable extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TorrentTable;
|
export default TorrentTable;
|
||||||
|
|||||||
Reference in New Issue
Block a user