import React from 'react'; import WifiOffIcon from '@material-ui/icons/WifiOff'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import Item from '../marketplace/Item'; import Items from '../marketplace/Items'; import MarketplaceFunctions from '../../../modules/helpers/marketplace'; import { toast } from 'react-toastify'; import * as Constants from '../../../modules/constants'; export default class Marketplace extends React.PureComponent { constructor(...args) { super(...args); this.state = { settings: [], photo_packs: [], quote_packs: [], see_more: [], see_more_type: '', current_data: { type: '', name: '', content: {} }, button: '', featured: {}, done: false, item_data: { name: 'Name', author: 'Author', description: 'Description', updated: '???', version: '1.0.0', icon: '' } } this.buttons = { uninstall: , install: } } async toggle(type, type2, data) { switch (type) { case 'seemore': document.getElementById('marketplace').style.display = 'none'; document.getElementById('seemore').style.display = 'block'; this.setState({ see_more: this.state[type2], see_more_type: type2 }); break; case 'item': let info; // get item info try { info = await (await fetch(`${Constants.MARKETPLACE_URL}/item/${type2}/${data}`)).json(); } catch (e) { return toast(this.props.toastLanguage.error); } // check if already installed let button = this.buttons.install; const installed = JSON.parse(localStorage.getItem('installed')); if (installed.some(item => item.name === data)) { button = this.buttons.uninstall; } this.setState({ current_data: { type: type2, name: data, content: info }, item_data: { name: info.data.name, author: info.data.author, description: MarketplaceFunctions.urlParser(info.data.description.replace(/\n/g, '
')), updated: info.updated, version: info.data.version, icon: info.data.screenshot_url }, button: button }); document.getElementById('marketplace').style.display = 'none'; document.getElementById('seemore').style.display = 'none'; document.getElementById('item').style.display = 'block'; break; default: document.getElementById('marketplace').style.display = 'block'; document.getElementById('item').style.display = 'none'; document.getElementById('seemore').style.display = 'none'; break; } } async getItems() { const { data } = await (await fetch(Constants.MARKETPLACE_URL + '/all')).json(); const featured = await (await fetch(Constants.MARKETPLACE_URL + '/featured')).json(); this.setState({ settings: data.settings, photo_packs: data.photo_packs, quote_packs: data.quote_packs, see_more: data.photo_packs, featured: featured.data, done: true }); } manage(type) { switch (type) { case 'install': MarketplaceFunctions.install(this.state.current_data.type, this.state.current_data.content.data); break; case 'uninstall': MarketplaceFunctions.uninstall(this.state.current_data.content.data.name, this.state.current_data.type); break; default: break; } toast(this.props.toastLanguage[type + 'ed']); this.setState({ button: (type === 'install') ? this.buttons.uninstall : this.buttons.install }); } componentDidMount() { if (localStorage.getItem('animations') === 'true') { document.getElementById('marketplace').classList.add('marketplaceanimation'); } if (navigator.onLine === false || localStorage.getItem('offlineMode') === 'true') { return; } this.getItems(); } render() { const errorMessage = (msg) => { return (
{msg}
); } if (navigator.onLine === false) { return errorMessage(

{this.props.language.offline.title}

{this.props.language.offline.description}

); } if (localStorage.getItem('offlineMode') === 'true') { return errorMessage(

Offline mode is enabled

Please turn off offline mode to access the marketplace

); } if (this.state.done === false) { return errorMessage(

{this.props.updateLanguage.loading}

); } return (

{this.state.featured.title}

{this.state.featured.name}

this.toggle('item', 'photo_packs', input)} seeMoreFunction={() => this.toggle('seemore', 'photo_packs')} /> this.toggle('item', 'settings', input)} seeMoreFunction={() => this.toggle('seemore', 'settings')} /> this.toggle('item', 'quote_packs', input)} seeMoreFunction={() => this.toggle('seemore', 'quote_packs')} />
this.toggle()} language={this.props.language.product} />
this.toggle()} /> this.toggle('item', this.state.see_more_type, input)} items={this.state.see_more} />
); } }