From 3ebbead33d5ab4539f1191340dfc783cad6574af Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Wed, 29 May 2019 16:47:33 +0300 Subject: [PATCH] Links extracted in a separete component --- src/common/MetaPreview/MetaPreview.js | 106 +++++++++++++++----------- src/common/MetaPreview/styles.less | 52 +++++++------ 2 files changed, 89 insertions(+), 69 deletions(-) diff --git a/src/common/MetaPreview/MetaPreview.js b/src/common/MetaPreview/MetaPreview.js index 3817c2d46..26cb184d3 100644 --- a/src/common/MetaPreview/MetaPreview.js +++ b/src/common/MetaPreview/MetaPreview.js @@ -4,21 +4,54 @@ const Icon = require('stremio-icons/dom'); const { Input } = require('stremio-navigation'); const styles = require('./styles'); -const MetaPreview = ({ className, compact, id, type, name, logo = '', background = '', duration = '', releaseInfo = '', released, description, genres = [], writers = [], directors = [], cast = [], imdbId = '', imdbRating = '', inLibrary = false, trailer = '', share = '', toggleLibraryOnClick }) => { +const MetaLinks = ({ label, links, href }) => ( + +
{label}
+
+ {links.map((link, index) => ( + + {link} + {index < links.length - 1 ? ',' : null} + + ))} +
+
+); + +const MetaPreview = ({ className, compact, id, type, name, logo = '', background = '', duration = '', releaseInfo = '', released = '', description = '', genres = [], writers = [], directors = [], cast = [], imdbId = '', imdbRating = '', inLibrary = false, trailer = '', share = '', toggleLibraryOnClick }) => { + const releaseInfoText = React.useMemo(() => { + const releasedDate = new Date(released); + return releaseInfo.length > 0 ? + releaseInfo + : + !isNaN(releasedDate.getFullYear()) ? + releasedDate.getFullYear() + : + ''; + }, [releaseInfo, released]); const logoOnError = React.useCallback((event) => { event.currentTarget.style.display = 'none'; }, []); - const releaseInfoText = releaseInfo.length > 0 ? - releaseInfo - : - released instanceof Date && !isNaN(released.getFullYear()) ? - released.getFullYear() - : - ''; + const hrefForGenre = React.useCallback((genre) => { + return `#/discover/${type}//${genre}`; + }, [type]); + const hrefForCrew = React.useCallback((name) => { + return `#/search?q=${name}`; + }, []); return (
- + { + logo.length > 0 ? + + : + null + } { releaseInfoText.length > 0 || duration.length > 0 ?
@@ -41,7 +74,7 @@ const MetaPreview = ({ className, compact, id, type, name, logo = '', background { name.length > 0 ?
-
{name}
+
{name}
: null @@ -56,45 +89,30 @@ const MetaPreview = ({ className, compact, id, type, name, logo = '', background } { genres.length > 0 ? -
-
Genres:
- {genres.map((genre) => ( - - {genre} - - ))} -
+ + : + null + } + { + cast.length > 0 ? + + : + null + } + { + writers.length > 0 && !compact ? + + : + null + } + { + directors.length > 0 && !compact ? + : null }
{/* - { - writers.length > 0 ? -
-
Writers
- {writers.map((writer) => ( - - {writer} - - ))} -
- : - null - } - { - cast.length > 0 ? -
-
Cast
- {cast.map((actor) => ( - - {actor} - - ))} -
- : - null - }
{ trailer.length > 0 ? diff --git a/src/common/MetaPreview/styles.less b/src/common/MetaPreview/styles.less index dab5b60d0..131bda2c9 100644 --- a/src/common/MetaPreview/styles.less +++ b/src/common/MetaPreview/styles.less @@ -4,15 +4,15 @@ background-repeat: no-repeat; background-position: center; background-origin: border-box; - color: var(--color-surfacelighter); &.compact { .meta-preview-content { + overflow-x: hidden; + overflow-y: auto; .logo { width: 100%; object-position: center; - background-color: var(--color-surfacedark20); } .duration-release-info-container { @@ -31,80 +31,82 @@ height: 100%; padding: 0.8em; background-color: var(--color-backgrounddarker60); + color: var(--color-surfacelighter); .logo { + display: block; max-width: 100%; height: 7em; margin-bottom: 0.8em; object-fit: contain; object-position: left center; + background-color: var(--color-surfacedarker40) } .duration-release-info-container { - width: 100%; display: flex; flex-direction: row; - align-items: flex-start; justify-content: flex-start; flex-wrap: wrap; .duration, .release-info { flex-grow: 0; flex-shrink: 1; + max-width: 100%; margin-bottom: 0.8em; margin-right: 0.8em; - line-height: 1.1em; - max-height: 2.2em; - text-align: center; word-wrap: break-word; word-break: break-word; + overflow: visible; } } .name-container { - width: 100%; margin-bottom: 0.8em; + overflow: visible; .name { font-size: 1.3em; - line-height: 1.2em; - max-height: 3.6em; word-wrap: break-word; word-break: break-word; + overflow: visible; } } .description-container { - width: 100%; margin-bottom: 0.8em; + overflow: visible; .description { font-size: 0.9em; - line-height: 1.15em; - max-height: 4.8em; word-wrap: break-word; word-break: break-word; + overflow: visible; } } + .links-label { + font-size: 1.1em; + color: var(--color-surfacelight); + word-wrap: break-word; + word-break: break-word; + overflow: visible; + } + .links-container { - width: 100%; - max-height: 3.2em; + display: flex; + flex-direction: row; + flex-wrap: wrap; margin-bottom: 0.8em; - .title { - width: 100%; - white-space: nowrap; - text-overflow: ellipsis; - color: var(--color-surfacelight); - } - .link { - display: inline-block; + flex-grow: 0; + flex-shrink: 1; max-width: 100%; - padding-right: 0.4em; + margin-right: 0.4em; font-size: 0.9em; - line-height: 1.15em; + line-height: 1.2em; + overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--color-surfacelighter);