Compare commits

...

5 Commits

Author SHA1 Message Date
ae7c752e43 Handle the torrent state in the torrent page
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2020-04-16 11:06:41 +02:00
ec7fb68da6 Fix the file size conversion 2020-04-16 11:06:07 +02:00
99e74356e6 Fix the torrent count if there's no torrent data 2020-04-16 11:03:41 +02:00
1cc826e97a Update polochon and papi to the latest versions 2020-04-16 11:03:03 +02:00
33a84f682d Fix momentjs deprecation warning 2020-04-15 12:46:43 +02:00
9 changed files with 39 additions and 42 deletions

View File

@ -1,15 +1,15 @@
import React from "react"; import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { upperCaseFirst } from "../../utils";
export const Genres = ({ genres = [] }) => { export const Genres = ({ genres = [] }) => {
if (!genres || genres.length === 0) { if (!genres || genres.length === 0) {
return null; return null;
} }
// Uppercase first genres // Uppercase first genres
const prettyGenres = genres const prettyGenres = genres.map((w) => upperCaseFirst(w)).join(", ");
.map((word) => word[0].toUpperCase() + word.substr(1))
.join(", ");
return ( return (
<span> <span>

View File

@ -3,22 +3,11 @@ import PropTypes from "prop-types";
import moment from "moment"; import moment from "moment";
const prettyDate = (input) => { const prettyDate = (input) => {
switch (typeof input) { if (typeof input !== "string" || input === "") {
case "string": return input;
if (input === "") {
return "";
}
break;
case "number":
if (input === 0) {
return "";
}
return input;
default:
return input;
} }
const date = moment(input); const date = moment(input, "YYYY-MM-DD HH:mm:ss Z");
if (!date.isValid()) { if (!date.isValid()) {
return ""; return "";
} }

View File

@ -3,6 +3,8 @@ import PropTypes from "prop-types";
import { withRouter } from "react-router-dom"; import { withRouter } from "react-router-dom";
import { Form, FormGroup, FormControl, FormLabel } from "react-bootstrap"; import { Form, FormGroup, FormControl, FormLabel } from "react-bootstrap";
import { upperCaseFirst } from "../../utils";
const ExplorerOptions = ({ const ExplorerOptions = ({
display, display,
params, params,
@ -45,7 +47,7 @@ const ExplorerOptions = ({
return name return name
.replace("_", " ") .replace("_", " ")
.split(" ") .split(" ")
.map((w) => w[0].toUpperCase() + w.substr(1)) .map((w) => upperCaseFirst(w))
.join(" "); .join(" ");
}; };

View File

@ -2,6 +2,8 @@ import React from "react";
import Loader from "../loader/loader"; import Loader from "../loader/loader";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { upperCaseFirst } from "../../utils";
// TODO: udpate this // TODO: udpate this
import { OverlayTrigger, Tooltip } from "react-bootstrap"; import { OverlayTrigger, Tooltip } from "react-bootstrap";
@ -24,13 +26,11 @@ Modules.propTypes = {
}; };
export default Modules; export default Modules;
const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
const ModulesByVideoType = ({ type, modules }) => ( const ModulesByVideoType = ({ type, modules }) => (
<div className="col-12 col-md-6"> <div className="col-12 col-md-6">
<div className="card mb-3"> <div className="card mb-3">
<div className="card-header"> <div className="card-header">
<h3>{`${capitalize(type)} modules`}</h3> <h3>{`${upperCaseFirst(type)} modules`}</h3>
</div> </div>
<div className="card-body"> <div className="card-body">
{Object.keys(modules).map((moduleType, i) => ( {Object.keys(modules).map((moduleType, i) => (
@ -47,7 +47,7 @@ ModulesByVideoType.propTypes = {
const ModuleByType = ({ type, modules }) => ( const ModuleByType = ({ type, modules }) => (
<div> <div>
<h4>{capitalize(type)}</h4> <h4>{upperCaseFirst(type)}</h4>
<table className="table"> <table className="table">
<tbody> <tbody>
{modules.map((module, type) => { {modules.map((module, type) => {

View File

@ -1,13 +1,16 @@
import React from "react"; import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { prettySize } from "../../../utils"; import { prettySize, upperCaseFirst } from "../../../utils";
export const Progress = ({ torrent }) => { export const Progress = ({ torrent }) => {
var progressStyle = torrent.status.is_finished const downloading = torrent.status.state === "downloading";
? "success" let progressBarClass = torrent.status.is_finished
: "info progress-bar-striped progress-bar-animated"; ? "progress-bar bg-success"
const progressBarClass = "progress-bar bg-" + progressStyle; : "progress-bar bg-info";
if (torrent.status.state === "downloading") {
progressBarClass += " progress-bar-striped progress-bar-animated";
}
var percentDone = torrent.status.percent_done; var percentDone = torrent.status.percent_done;
const started = percentDone !== 0; const started = percentDone !== 0;
@ -31,14 +34,14 @@ export const Progress = ({ torrent }) => {
aria-valuemax="100" aria-valuemax="100"
></div> ></div>
</div> </div>
{started && ( {downloading && (
<p> <p>
{downloadedSize} / {totalSize} - {percentDone} - {downloadRate} {downloadedSize} / {totalSize} - {percentDone} - {downloadRate}
</p> </p>
)} )}
{!started && ( {!downloading && (
<p> <p className="text-muted">
<small>Not yet started</small> <small>{upperCaseFirst(torrent.status.state)}</small>
</p> </p>
)} )}
</div> </div>

View File

@ -49,7 +49,9 @@ export default (state = defaultState, action) =>
case "TORRENTS_FETCH_FULFILLED": case "TORRENTS_FETCH_FULFILLED":
draft.fetching = false; draft.fetching = false;
draft.torrents = formatTorrents(action.payload.response.data); draft.torrents = formatTorrents(action.payload.response.data);
draft.count = action.payload.response.data.length; draft.count = action.payload.response.data
? action.payload.response.data.length
: 0;
break; break;
case "TORRENTS_SEARCH_PENDING": case "TORRENTS_SEARCH_PENDING":

View File

@ -28,9 +28,9 @@ export const prettySize = (fileSizeInBytes) => {
var i = -1; var i = -1;
var byteUnits = [" kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"]; var byteUnits = [" kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"];
do { do {
fileSizeInBytes = fileSizeInBytes / 1024; fileSizeInBytes = fileSizeInBytes / 1000;
i++; i++;
} while (fileSizeInBytes > 1024); } while (fileSizeInBytes > 1000);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
}; };
@ -55,3 +55,6 @@ export const formatTorrents = (input) => {
return torrentMap; return torrentMap;
}; };
export const upperCaseFirst = (string) =>
string.charAt(0).toUpperCase() + string.slice(1);

4
go.mod
View File

@ -15,8 +15,8 @@ require (
github.com/mattn/go-sqlite3 v1.10.0 // indirect github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/odwrtw/errors v0.0.0-20170604160533-c747b9d17833 github.com/odwrtw/errors v0.0.0-20170604160533-c747b9d17833
github.com/odwrtw/papi v0.0.0-20200413153625-62744e1c1b73 github.com/odwrtw/papi v0.0.0-20200416090004-26e95d2feb66
github.com/odwrtw/polochon v0.0.0-20200413153516-6d6ff1d17684 github.com/odwrtw/polochon v0.0.0-20200416085801-6331a40936bf
github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029 github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029
github.com/pioz/tvdb v0.0.0-20190503215423-f45c687faba9 // indirect github.com/pioz/tvdb v0.0.0-20190503215423-f45c687faba9 // indirect
github.com/robfig/cron v1.1.0 github.com/robfig/cron v1.1.0

10
go.sum
View File

@ -134,12 +134,10 @@ github.com/odwrtw/guessit v0.0.0-20200131084001-f88613483547/go.mod h1:W22g7wtc0
github.com/odwrtw/imdb-watchlist v0.0.0-20190417175016-b7a9f7503d69 h1:ow6b/4Jj7J5iYwU678/rbijvaNUJrYkg13j9Nivkung= github.com/odwrtw/imdb-watchlist v0.0.0-20190417175016-b7a9f7503d69 h1:ow6b/4Jj7J5iYwU678/rbijvaNUJrYkg13j9Nivkung=
github.com/odwrtw/imdb-watchlist v0.0.0-20190417175016-b7a9f7503d69/go.mod h1:o2tLH95CtNdqhDb0aS2NbU+1I4PmaNsODpr33Ry0JC0= github.com/odwrtw/imdb-watchlist v0.0.0-20190417175016-b7a9f7503d69/go.mod h1:o2tLH95CtNdqhDb0aS2NbU+1I4PmaNsODpr33Ry0JC0=
github.com/odwrtw/papi v0.0.0-20190413103029-bd5bfea85ae6/go.mod h1:CXotdtODLpW0/yuFV5XH8Rmrj0eAfPLvdMKykPM2WCk= github.com/odwrtw/papi v0.0.0-20190413103029-bd5bfea85ae6/go.mod h1:CXotdtODLpW0/yuFV5XH8Rmrj0eAfPLvdMKykPM2WCk=
github.com/odwrtw/papi v0.0.0-20200410143325-49e6f827259d/go.mod h1:eY0skvVHJBwbSJ18uq2c1T4SvhdEV8R0XFSb0zKh5Yo= github.com/odwrtw/papi v0.0.0-20200416090004-26e95d2feb66 h1:E+UrY1WG5xp65UXs2rbtVVD4FdSffMR9E0lbd7xdf80=
github.com/odwrtw/papi v0.0.0-20200413153625-62744e1c1b73 h1:19mh4fw/WGFtYg/7oHg1Y5rU9ZRxD3LqrtwY2NI6l6w= github.com/odwrtw/papi v0.0.0-20200416090004-26e95d2feb66/go.mod h1:eY0skvVHJBwbSJ18uq2c1T4SvhdEV8R0XFSb0zKh5Yo=
github.com/odwrtw/papi v0.0.0-20200413153625-62744e1c1b73/go.mod h1:eY0skvVHJBwbSJ18uq2c1T4SvhdEV8R0XFSb0zKh5Yo= github.com/odwrtw/polochon v0.0.0-20200416085801-6331a40936bf h1:zzsX9o1Gxe1esokjdcOMa5hMC2aqubWXQoAEqMCMyyY=
github.com/odwrtw/polochon v0.0.0-20200410143337-006e3fb9fb55/go.mod h1:sAYf/A5tDmins2GHZn2mEFarmYltAZv+bcmSKSxDUaI= github.com/odwrtw/polochon v0.0.0-20200416085801-6331a40936bf/go.mod h1:rBjekia21ToZoTxJqR/5Ued8EYwKTtamq+bo/XINOjA=
github.com/odwrtw/polochon v0.0.0-20200413153516-6d6ff1d17684 h1:b9JDu8423NGXOYN0gtoiVrLKbZ/CfAyc2ouCRuE+mI8=
github.com/odwrtw/polochon v0.0.0-20200413153516-6d6ff1d17684/go.mod h1:rBjekia21ToZoTxJqR/5Ued8EYwKTtamq+bo/XINOjA=
github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f h1:fwEIGT+o3e8+XkBqrwsE3/+9ketTQXflPhCkv3/w990= github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f h1:fwEIGT+o3e8+XkBqrwsE3/+9ketTQXflPhCkv3/w990=
github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f/go.mod h1:updLvMbQo2xHoz94MX9+GqmSoKhf6E8fs/J+wLvvu6A= github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f/go.mod h1:updLvMbQo2xHoz94MX9+GqmSoKhf6E8fs/J+wLvvu6A=
github.com/odwrtw/trakttv v0.0.0-20200404161731-0d594827e4f9 h1:PuQLHO75MXUsJpf9BcTVxvR/FCkdn1MZnZt6h3o6cJI= github.com/odwrtw/trakttv v0.0.0-20200404161731-0d594827e4f9 h1:PuQLHO75MXUsJpf9BcTVxvR/FCkdn1MZnZt6h3o6cJI=