From b6121fdb5e2fd5d513a5b0e5ebf20c910f5e8c9e Mon Sep 17 00:00:00 2001 From: aldifirmansyah <aldifirmansyh@gmail.com> Date: Thu, 12 Dec 2019 15:23:05 +0700 Subject: [PATCH] [ADD] getDuration function in contentTabItem components --- .../ContentTabItem/ContentTabChild.js | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/components/ContentTabItem/ContentTabChild.js b/src/components/ContentTabItem/ContentTabChild.js index 12d2054..e637720 100644 --- a/src/components/ContentTabItem/ContentTabChild.js +++ b/src/components/ContentTabItem/ContentTabChild.js @@ -22,17 +22,38 @@ const ContentTabChild = ({ videoName, duration, sectionName -}) => ( - <Container - onClick={() => changeVideo(`${sectionName} | ${videoName}`, videoFile)} - > - <Typography style={{ paddingLeft: "0.5rem" }}> - {number}. {videoName} |{" "} - <span style={{ fontSize: "0.75em" }}>{duration} seconds</span> - </Typography> - </Container> -); +}) => { + const getDuration = duration => { + if (!duration) return ""; + let result = ""; + + // set detik + let temp = duration; + if (temp % 60) result = `${temp % 60} detik`; + if (temp < 60) return result; + + // set menit + temp = Math.floor(temp / 60); + if (temp % 60) result = `${temp % 60} menit ${result}`; + if (temp < 60) return result; + + // set jam + temp = Math.floor(temp / 60); + result = `${temp % 60} jam ${result}`; + return result; + }; + return ( + <Container + onClick={() => changeVideo(`${sectionName} | ${videoName}`, videoFile)} + > + <Typography style={{ paddingLeft: "0.5rem" }}> + {number}. {videoName} |{" "} + <span style={{ fontSize: "0.75em" }}>{getDuration(duration)}</span> + </Typography> + </Container> + ); +}; ContentTabChild.propTypes = { name: PropTypes.string }; -- GitLab