From 72c78142392841c60a434d5393f50e6bfaaba263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Sat, 3 Jun 2017 15:41:46 +0200 Subject: [PATCH] Refactor the ListDetails component --- src/public/js/components/list/details.js | 129 ++++++++++++++--------- 1 file changed, 81 insertions(+), 48 deletions(-) diff --git a/src/public/js/components/list/details.js b/src/public/js/components/list/details.js index dc93eab..f848afb 100644 --- a/src/public/js/components/list/details.js +++ b/src/public/js/components/list/details.js @@ -1,63 +1,96 @@ import React from "react" export default function ListDetails(props) { - let genres = props.data.get("genres"); - if (genres !== undefined) { - // Uppercase first genres - genres = genres.toJS().map( - (word) => word[0].toUpperCase() + word.substr(1) - ).join(", "); - } - - let wishlistStr = ""; - if (props.data.get("wishlisted") === true) { - wishlistStr = "Wishlisted"; - } - - const trackedSeason = props.data.get("tracked_season"); - const trackedEpisode = props.data.get("tracked_episode"); - if (trackedEpisode !== null && trackedSeason !== null - && trackedEpisode !== undefined && trackedSeason !== undefined) { - if ((trackedSeason === 0) && (trackedEpisode === 0)) { - wishlistStr = "Whole show tracked"; - } else { - wishlistStr = `Tracked from season ${trackedSeason} episode ${trackedEpisode}`; - } - } - return (

{props.data.get("title")}

{props.data.get("title")}

- {wishlistStr !== "" && - - {wishlistStr} - - } +

{props.data.get("year")}

- {props.data.get("runtime") !== undefined && -

- -  {props.data.get("runtime")} min -

- } - {genres !== undefined && -

- -  {genres} -

- } -

- -  {Number(props.data.get("rating")).toFixed(1)}  - {props.data.get("votes") !== undefined && - ({props.data.get("votes")} counts) - } -

+ + +

{props.data.get("plot")}

{props.children}
); } + +function Runtime(props) { + if (props.runtime === undefined) { + return null; + } + + return ( +

+ +  {props.runtime} min +

+ ); +} + +function Ratings(props) { + if (props.rating === undefined) { + return null; + } + + return ( +

+ +  {Number(props.rating).toFixed(1)}  + {props.votes !== undefined && + ({props.votes} counts) + } +

+ ); +} + +function TrackingLabel(props) { + let wishlistStr = props.wishlisted ? "Wishlisted" : ""; + + if (props.trackedEpisode !== null && props.trackedSeason !== null + && props.trackedEpisode !== undefined && props.trackedSeason !== undefined) { + if ((props.trackedSeason === 0) && (props.trackedEpisode === 0)) { + wishlistStr = "Whole show tracked"; + } else { + wishlistStr = `Tracked from season ${props.trackedSeason} episode ${props.trackedEpisode}`; + } + } + + if (wishlistStr === "") { + return null; + } + + return ( + + {wishlistStr} + + ); +} + +function Genres(props) { + if (props.genres === undefined) { + return null; + } + + // Uppercase first genres + const prettyGenres = props.genres.toJS().map( + (word) => word[0].toUpperCase() + word.substr(1) + ).join(", "); + + return ( +

+ +  {prettyGenres} +

+ ); +}