From 35d4a7780c9a194bc99195023702476988fb554c Mon Sep 17 00:00:00 2001 From: David Ralph Date: Sat, 10 Feb 2024 22:34:49 +0000 Subject: [PATCH] refactor(marketplace): cleanup item page render --- src/components/helpers/carousel/Carousel.jsx | 39 +++-- .../modals/main/marketplace/Item.jsx | 148 ++++++++---------- .../main/marketplace/sections/Added.jsx | 2 +- 3 files changed, 87 insertions(+), 102 deletions(-) diff --git a/src/components/helpers/carousel/Carousel.jsx b/src/components/helpers/carousel/Carousel.jsx index 2ff9d8f3..c7240fdc 100644 --- a/src/components/helpers/carousel/Carousel.jsx +++ b/src/components/helpers/carousel/Carousel.jsx @@ -3,6 +3,8 @@ import { MdOutlineArrowForwardIos, MdOutlineArrowBackIos } from 'react-icons/md' import useEmblaCarousel from 'embla-carousel-react'; import Autoplay from 'embla-carousel-autoplay'; +import variables from 'modules/variables'; + import './carousel.scss'; function EmblaCarousel({ data }) { @@ -53,26 +55,33 @@ function EmblaCarousel({ data }) { {data.map((photo, index) => (
- Marketplace example screenshot + Marketplace example screenshot
))} - - + {data.length > 1 && ( + <> + + + + )} ); } diff --git a/src/components/modals/main/marketplace/Item.jsx b/src/components/modals/main/marketplace/Item.jsx index 0f2d1202..74b5c377 100644 --- a/src/components/modals/main/marketplace/Item.jsx +++ b/src/components/modals/main/marketplace/Item.jsx @@ -11,7 +11,6 @@ import { MdFormatQuote, MdImage, MdTranslate, - MdOutlineKeyboardArrowRight, MdExpandMore, MdExpandLess, MdStyle, @@ -47,24 +46,21 @@ class Item extends PureComponent { } incrementCount(type) { - if (this.state.count !== this.props.data.data[type].length) { - this.setState({ count: this.props.data.data[type].length }); - } else { - this.setState({ count: 5 }); - } + const newCount = + this.state.count !== this.props.data.data[type].length + ? this.props.data.data[type].length + : 5; + + this.setState({ count: newCount }); } getName(name) { - switch (name) { - case 'photos': - return 'photo_packs'; - case 'quotes': - return 'quote_packs'; - case 'settings': - return 'preset_settings'; - default: - return name; - } + const nameMappings = { + photos: 'photo_packs', + quotes: 'quote_packs', + settings: 'preset_settings', + }; + return nameMappings[name] || name; } render() { @@ -89,6 +85,16 @@ class Item extends PureComponent { ); } + const moreInfoItem = (icon, header, text) => ( +
+ {icon} +
+ {header} + {text} +
+
+ ); + return (
-
- -
- - {variables.getMessage('modals.main.marketplace.product.version')} - - {updateButton ? ( - - {this.props.data.version} (Installed: {this.props.data.addonInstalledVersion}) - - ) : ( - {this.props.data.version} - )} -
-
-
- -
- - {variables.getMessage('modals.main.marketplace.product.author')} - - {this.props.data.author} -
-
- {this.props.data.data.quotes && ( -
- -
- - {variables.getMessage('modals.main.marketplace.product.no_quotes')} - - {this.props.data.data.quotes.length} -
-
- )} - {this.props.data.data.photos && ( -
- -
- - {variables.getMessage('modals.main.marketplace.product.no_images')} - - {this.props.data.data.photos.length} -
-
- )} - {this.props.data.data.quotes && this.props.data.data.language !== '' ? ( -
- -
- - {variables.getMessage('modals.main.settings.sections.language.title')} - - {this.props.data.data.language} -
-
- ) : null} -
- -
- - {' '} - {variables.getMessage('modals.main.settings.sections.background.type.title')} - + {moreInfoItem( + , + variables.getMessage('modals.main.marketplace.product.version'), + updateButton ? ( - {' '} - {variables.getMessage( - 'modals.main.marketplace.' + this.getName(this.props.data.data.type), - ) || 'marketplace'} + {this.props.data.version} (Installed: {this.props.data.addonInstalledVersion}) -
-
+ ) : ( + {this.props.data.version} + ), + )} + {moreInfoItem( + , + variables.getMessage('modals.main.marketplace.product.author'), + this.props.data.author, + )} + {this.props.data.data.quotes && + moreInfoItem( + , + variables.getMessage('modals.main.marketplace.product.no_quotes'), + this.props.data.data.quotes.length, + )} + {this.props.data.data.photos && + moreInfoItem( + , + variables.getMessage('modals.main.marketplace.product.no_images'), + this.props.data.data.photos.length, + )} + {this.props.data.data.quotes && this.props.data.data.language !== '' + ? moreInfoItem( + , + variables.getMessage('modals.main.settings.sections.language.title'), + this.props.data.data.language, + ) + : null} + {moreInfoItem( + , + variables.getMessage('modals.main.settings.sections.background.type.title'), + variables.getMessage( + 'modals.main.marketplace.' + this.getName(this.props.data.data.type), + ) || 'marketplace', + )}