import variables from 'config/variables'; import { PureComponent, Fragment } from 'react'; import { Tooltip } from 'components/Elements'; import ImageCarousel from 'features/helpers/carousel/Carousel'; import { toast } from 'react-toastify'; import { MdIosShare, MdFlag, MdAccountCircle, MdBugReport, MdFormatQuote, MdImage, MdTranslate, MdExpandMore, MdExpandLess, MdStyle, } from 'react-icons/md'; import Modal from 'react-modal'; import { Header } from 'components/Layout/Settings'; import { Button } from 'components/Elements'; import { install, uninstall } from 'utils/marketplace'; import { ShareModal } from 'components/Elements'; class Item extends PureComponent { constructor(props) { super(props); this.state = { showLightbox: false, showUpdateButton: this.props.addonInstalled === true && this.props.addonInstalledVersion !== this.props.data.version, shareModal: false, count: 5, }; } updateAddon() { uninstall(this.props.data.type, this.props.data.display_name); install(this.props.data.type, this.props.data); toast(variables.getMessage('toasts.updated')); this.setState({ showUpdateButton: false, }); } incrementCount(type) { const newCount = this.state.count !== this.props.data.data[type].length ? this.props.data.data[type].length : 5; this.setState({ count: newCount }); } getName(name) { const nameMappings = { photos: 'photo_packs', quotes: 'quote_packs', settings: 'preset_settings', }; return nameMappings[name] || name; } render() { if (!this.props.data.display_name) { return null; } // prevent console error let iconsrc = variables.constants.DDG_IMAGE_PROXY + this.props.data.icon; if (!this.props.data.icon) { iconsrc = null; } let updateButton; if (this.state.showUpdateButton) { updateButton = ( ); } const moreInfoItem = (icon, header, text) => (
{icon}
{header} {text}
); return (
this.setState({ shareModal: false })} > this.setState({ shareModal: false })} />
{this.props.data.data.photos && (
)} {this.props.data.data.settings && ( product this.setState({ showLightbox: true })} /> )} {this.props.data.data.quotes && ( <> {this.props.data.data.quotes.slice(0, this.state.count).map((quote, index) => ( ))}
{variables.getMessage('modals.main.settings.sections.quote.title')} {variables.getMessage('modals.main.settings.sections.quote.author')}
{quote.quote} {quote.author}
this.incrementCount('quotes')}> {this.state.count !== this.props.data.data.quotes.length ? ( <> {' '} {variables.getMessage('modals.main.marketplace.product.show_all')} ) : ( <> {' '} {variables.getMessage('modals.main.marketplace.product.show_less')} )}
)} {this.props.data.data.settings && ( <> {Object.entries(this.props.data.data.settings) .slice(0, this.state.count) .map(([key, value]) => ( ))}
{variables.getMessage('modals.main.marketplace.product.setting')} {variables.getMessage('modals.main.marketplace.product.value')}
{key} {value}
this.incrementCount('settings')}> {this.state.count !== this.props.data.data.settings.length ? ( <> {' '} {variables.getMessage('modals.main.marketplace.product.show_all')} ) : ( <> {' '} {variables.getMessage('modals.main.marketplace.product.show_less')} )}
)}

{variables.getMessage('modals.main.marketplace.product.description')}

{moreInfoItem( , variables.getMessage('modals.main.marketplace.product.version'), updateButton ? ( {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', )}
icon {this.props.button}
{this.props.data.data.collection && (
{variables.getMessage('modals.main.marketplace.product.part_of')} {this.props.data.data.collection}
)}
); } } export default Item;