From ae7c752e43ae672797835d62cae5db6a507fce8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Thu, 16 Apr 2020 11:06:41 +0200 Subject: [PATCH] Handle the torrent state in the torrent page --- frontend/js/components/details/genres.js | 6 +++--- .../js/components/list/explorerOptions.js | 4 +++- frontend/js/components/modules/modules.js | 8 +++---- .../js/components/torrents/list/progress.js | 21 +++++++++++-------- frontend/js/utils.js | 3 +++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/frontend/js/components/details/genres.js b/frontend/js/components/details/genres.js index c2b94be..11818b7 100644 --- a/frontend/js/components/details/genres.js +++ b/frontend/js/components/details/genres.js @@ -1,15 +1,15 @@ import React from "react"; import PropTypes from "prop-types"; +import { upperCaseFirst } from "../../utils"; + export const Genres = ({ genres = [] }) => { if (!genres || genres.length === 0) { return null; } // Uppercase first genres - const prettyGenres = genres - .map((word) => word[0].toUpperCase() + word.substr(1)) - .join(", "); + const prettyGenres = genres.map((w) => upperCaseFirst(w)).join(", "); return ( diff --git a/frontend/js/components/list/explorerOptions.js b/frontend/js/components/list/explorerOptions.js index 688c499..3ed6934 100644 --- a/frontend/js/components/list/explorerOptions.js +++ b/frontend/js/components/list/explorerOptions.js @@ -3,6 +3,8 @@ import PropTypes from "prop-types"; import { withRouter } from "react-router-dom"; import { Form, FormGroup, FormControl, FormLabel } from "react-bootstrap"; +import { upperCaseFirst } from "../../utils"; + const ExplorerOptions = ({ display, params, @@ -45,7 +47,7 @@ const ExplorerOptions = ({ return name .replace("_", " ") .split(" ") - .map((w) => w[0].toUpperCase() + w.substr(1)) + .map((w) => upperCaseFirst(w)) .join(" "); }; diff --git a/frontend/js/components/modules/modules.js b/frontend/js/components/modules/modules.js index 8b15afa..bcc20e4 100644 --- a/frontend/js/components/modules/modules.js +++ b/frontend/js/components/modules/modules.js @@ -2,6 +2,8 @@ import React from "react"; import Loader from "../loader/loader"; import PropTypes from "prop-types"; +import { upperCaseFirst } from "../../utils"; + // TODO: udpate this import { OverlayTrigger, Tooltip } from "react-bootstrap"; @@ -24,13 +26,11 @@ Modules.propTypes = { }; export default Modules; -const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1); - const ModulesByVideoType = ({ type, modules }) => (
-

{`${capitalize(type)} modules`}

+

{`${upperCaseFirst(type)} modules`}

{Object.keys(modules).map((moduleType, i) => ( @@ -47,7 +47,7 @@ ModulesByVideoType.propTypes = { const ModuleByType = ({ type, modules }) => (
-

{capitalize(type)}

+

{upperCaseFirst(type)}

{modules.map((module, type) => { diff --git a/frontend/js/components/torrents/list/progress.js b/frontend/js/components/torrents/list/progress.js index 02f7cf8..817b757 100644 --- a/frontend/js/components/torrents/list/progress.js +++ b/frontend/js/components/torrents/list/progress.js @@ -1,13 +1,16 @@ import React from "react"; import PropTypes from "prop-types"; -import { prettySize } from "../../../utils"; +import { prettySize, upperCaseFirst } from "../../../utils"; export const Progress = ({ torrent }) => { - var progressStyle = torrent.status.is_finished - ? "success" - : "info progress-bar-striped progress-bar-animated"; - const progressBarClass = "progress-bar bg-" + progressStyle; + const downloading = torrent.status.state === "downloading"; + let progressBarClass = torrent.status.is_finished + ? "progress-bar bg-success" + : "progress-bar bg-info"; + if (torrent.status.state === "downloading") { + progressBarClass += " progress-bar-striped progress-bar-animated"; + } var percentDone = torrent.status.percent_done; const started = percentDone !== 0; @@ -31,14 +34,14 @@ export const Progress = ({ torrent }) => { aria-valuemax="100" > - {started && ( + {downloading && (

{downloadedSize} / {totalSize} - {percentDone} - {downloadRate}

)} - {!started && ( -

- Not yet started + {!downloading && ( +

+ {upperCaseFirst(torrent.status.state)}

)} diff --git a/frontend/js/utils.js b/frontend/js/utils.js index e31ee86..9e06768 100644 --- a/frontend/js/utils.js +++ b/frontend/js/utils.js @@ -55,3 +55,6 @@ export const formatTorrents = (input) => { return torrentMap; }; + +export const upperCaseFirst = (string) => + string.charAt(0).toUpperCase() + string.slice(1); -- 2.47.1