From 3b2d1f365c89bb146f6c9c852a4e6750a6cbdf49 Mon Sep 17 00:00:00 2001 From: higorgoulart Date: Tue, 4 Nov 2025 19:23:39 -0300 Subject: [PATCH] feat: icons group component --- src/components/DiscItem/DiscItem.js | 2 +- .../IconsGroup.less} | 6 ++- src/components/IconsGroup/IconsGroup.tsx | 36 ++++++++++++++ src/components/IconsGroup/index.ts | 6 +++ src/components/MetaPreview/MetaPreview.js | 48 +++++++------------ .../MetaPreview/Ratings/Ratings.tsx | 27 ++++++----- src/components/MetaPreview/styles.less | 5 -- 7 files changed, 78 insertions(+), 52 deletions(-) rename src/components/{MetaPreview/Ratings/Ratings.less => IconsGroup/IconsGroup.less} (92%) create mode 100644 src/components/IconsGroup/IconsGroup.tsx create mode 100644 src/components/IconsGroup/index.ts diff --git a/src/components/DiscItem/DiscItem.js b/src/components/DiscItem/DiscItem.js index cc1cf5315..d09e35380 100644 --- a/src/components/DiscItem/DiscItem.js +++ b/src/components/DiscItem/DiscItem.js @@ -6,7 +6,7 @@ const classnames = require('classnames'); const MetaItem = require('stremio/components/MetaItem'); const { t } = require('i18next'); -const DiscItem = ({ id, watched, selected, toggleWatched, select, ...props }) => { +const DiscItem = ({ id, watched, selected, toggleWatched, ...props }) => { const options = React.useMemo(() => { return [ diff --git a/src/components/MetaPreview/Ratings/Ratings.less b/src/components/IconsGroup/IconsGroup.less similarity index 92% rename from src/components/MetaPreview/Ratings/Ratings.less rename to src/components/IconsGroup/IconsGroup.less index afe7b3637..8e09c9f93 100644 --- a/src/components/MetaPreview/Ratings/Ratings.less +++ b/src/components/IconsGroup/IconsGroup.less @@ -8,7 +8,7 @@ @width-mobile: 3rem; -.ratings-container { +.group-container { display: flex; flex-direction: row; align-items: center; @@ -17,6 +17,8 @@ border-radius: 2rem; height: @height; width: fit-content; + margin-bottom: 1rem; + margin-right: 1rem; .icon-container { display: flex; @@ -45,7 +47,7 @@ } @media @phone-landscape { - .ratings-container { + .group-container { height: @height-mobile; .icon-container { diff --git a/src/components/IconsGroup/IconsGroup.tsx b/src/components/IconsGroup/IconsGroup.tsx new file mode 100644 index 000000000..a667592de --- /dev/null +++ b/src/components/IconsGroup/IconsGroup.tsx @@ -0,0 +1,36 @@ +// Copyright (C) 2017-2023 Smart code 203358507 + +import classNames from 'classnames'; +import React from 'react'; +import Icon from '@stremio/stremio-icons/react'; +import styles from './IconsGroup.less'; + +type GroupItem = { + icon: string; + filled?: string; + disabled?: boolean; + className?: string; + onClick?: () => void; +}; + +type Props = { + items: GroupItem[]; + className?: string; +}; + +const IconsGroup = ({ items, className }: Props) => { + return ( +
+ {items.map((item, index) => ( +
+ +
+ ))} +
+ ); +}; + +export default IconsGroup; diff --git a/src/components/IconsGroup/index.ts b/src/components/IconsGroup/index.ts new file mode 100644 index 000000000..4407a8c6f --- /dev/null +++ b/src/components/IconsGroup/index.ts @@ -0,0 +1,6 @@ +// Copyright (C) 2017-2023 Smart code 203358507 + +import IconsGroup from './IconsGroup'; + +export { IconsGroup }; + diff --git a/src/components/MetaPreview/MetaPreview.js b/src/components/MetaPreview/MetaPreview.js index 829903cfa..5cedaa55e 100644 --- a/src/components/MetaPreview/MetaPreview.js +++ b/src/components/MetaPreview/MetaPreview.js @@ -8,6 +8,7 @@ const { useTranslation } = require('react-i18next'); const { default: Icon } = require('@stremio/stremio-icons/react'); const { default: Button } = require('stremio/components/Button'); const { default: Image } = require('stremio/components/Image'); +const { IconsGroup } = require('stremio/components/IconsGroup'); const ModalDialog = require('stremio/components/ModalDialog'); const SharePrompt = require('stremio/components/SharePrompt'); const CONSTANTS = require('stremio/common/CONSTANTS'); @@ -98,6 +99,16 @@ const MetaPreview = React.forwardRef(({ className, compact, name, logo, backgrou const renderLogoFallback = React.useCallback(() => (
{name}
), [name]); + const libAndWatchedGroup = React.useMemo(() => [ + { + icon: inLibrary ? 'remove-from-library' : 'add-to-library', + onClick: typeof toggleInLibrary === 'function' ? toggleInLibrary : null, + }, + { + icon: watched ? 'eye-off' : 'eye', + onClick: typeof toggleWatched === 'function' ? toggleWatched : undefined, + }, + ], [inLibrary, watched, toggleInLibrary, toggleWatched]); return (
{ @@ -209,30 +220,9 @@ const MetaPreview = React.forwardRef(({ className, compact, name, logo, backgrou null } { - typeof toggleInLibrary === 'function' ? - - : - null - } - { - typeof toggleWatched === 'function' ? - - : - null + typeof toggleInLibrary === 'function' && typeof toggleWatched === 'function' + ? + : null } { typeof showHref === 'string' && compact ? @@ -247,13 +237,9 @@ const MetaPreview = React.forwardRef(({ className, compact, name, logo, backgrou null } { - !compact && ratingInfo !== null ? - - : - null + !compact && ratingInfo !== null + ? + : null } { linksGroups.has(CONSTANTS.SHARE_LINK_CATEGORY) && !compact ? diff --git a/src/components/MetaPreview/Ratings/Ratings.tsx b/src/components/MetaPreview/Ratings/Ratings.tsx index 6bef0cc6d..49ed77ba1 100644 --- a/src/components/MetaPreview/Ratings/Ratings.tsx +++ b/src/components/MetaPreview/Ratings/Ratings.tsx @@ -2,9 +2,7 @@ import React, { useMemo } from 'react'; import useRating from './useRating'; -import styles from './Ratings.less'; -import Icon from '@stremio/stremio-icons/react'; -import classNames from 'classnames'; +import { IconsGroup } from 'stremio/components/IconsGroup'; type Props = { metaId?: string; @@ -15,17 +13,20 @@ type Props = { const Ratings = ({ ratingInfo, className }: Props) => { const { onLiked, onLoved, liked, loved } = useRating(ratingInfo); const disabled = useMemo(() => ratingInfo?.type !== 'Ready', [ratingInfo]); + const items = useMemo(() => [ + { + icon: liked ? 'thumbs-up' : 'thumbs-up-outline', + disabled, + onClick: onLiked, + }, + { + icon: loved ? 'heart' : 'heart-outline', + disabled, + onClick: onLoved, + }, + ], [liked, loved, disabled, onLiked, onLoved]); - return ( -
-
- -
-
- -
-
- ); + return ; }; export default Ratings; diff --git a/src/components/MetaPreview/styles.less b/src/components/MetaPreview/styles.less index 3fea95a5f..9347552a0 100644 --- a/src/components/MetaPreview/styles.less +++ b/src/components/MetaPreview/styles.less @@ -208,11 +208,6 @@ } } } - - .ratings { - margin-bottom: 1rem; - margin-right: 1rem; - } } .share-prompt {