2021-09-05 19:52:26 +00:00
|
|
|
import { PureComponent, Fragment } from 'react';
|
|
|
|
import { toast } from 'react-toastify';
|
2021-08-15 21:28:37 +00:00
|
|
|
import { ArrowBack } from '@material-ui/icons';
|
2021-05-01 11:31:46 +00:00
|
|
|
import Modal from 'react-modal';
|
2020-08-26 13:32:52 +00:00
|
|
|
|
2021-09-05 19:52:26 +00:00
|
|
|
import { install, uninstall } from 'modules/helpers/marketplace';
|
|
|
|
|
2021-05-01 11:31:46 +00:00
|
|
|
import Lightbox from './Lightbox';
|
2021-03-20 19:45:49 +00:00
|
|
|
|
2021-08-14 19:10:48 +00:00
|
|
|
export default class Item extends PureComponent {
|
2021-09-05 19:52:26 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2021-04-26 08:52:22 +00:00
|
|
|
this.state = {
|
2021-09-05 19:52:26 +00:00
|
|
|
showLightbox: false,
|
|
|
|
showUpdateButton: (this.props.addonInstalled === true && this.props.addonInstalledVersion !== this.props.data.version)
|
2021-04-26 08:52:22 +00:00
|
|
|
};
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|
2021-02-26 16:06:54 +00:00
|
|
|
|
2021-09-05 19:52:26 +00:00
|
|
|
updateAddon() {
|
|
|
|
uninstall(this.props.data.type, this.props.data.display_name);
|
|
|
|
install(this.props.data.type, this.props.data);
|
|
|
|
toast('Successfully updated!');
|
|
|
|
this.setState({
|
|
|
|
showUpdateButton: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-26 08:52:22 +00:00
|
|
|
render() {
|
|
|
|
const language = window.language.modals.main.marketplace.product;
|
|
|
|
|
2021-05-03 10:27:52 +00:00
|
|
|
if (!this.props.data.display_name) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-26 08:52:22 +00:00
|
|
|
let warningHTML;
|
2021-05-03 10:27:52 +00:00
|
|
|
if (this.props.data.quote_api) {
|
|
|
|
warningHTML = (
|
|
|
|
<div className='productInformation'>
|
|
|
|
<ul>
|
|
|
|
<li className='header'>{language.quote_warning.title}</li>
|
|
|
|
<li id='updated'>{language.quote_warning.description}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
2021-04-26 08:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prevent console error
|
2021-07-02 20:29:33 +00:00
|
|
|
let iconsrc = window.constants.DDG_IMAGE_PROXY + this.props.data.icon;
|
2021-04-26 08:52:22 +00:00
|
|
|
if (!this.props.data.icon) {
|
|
|
|
iconsrc = null;
|
|
|
|
}
|
2021-09-05 19:52:26 +00:00
|
|
|
|
|
|
|
let updateButton;
|
|
|
|
if (this.state.showUpdateButton) {
|
|
|
|
updateButton = (
|
|
|
|
<Fragment key='update'>
|
|
|
|
<br/><br/>
|
|
|
|
<button className='removeFromMue' onClick={() => this.updateAddon()}>
|
|
|
|
Update Add-on
|
|
|
|
</button>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
2021-04-26 08:52:22 +00:00
|
|
|
|
|
|
|
return (
|
2021-05-03 10:27:52 +00:00
|
|
|
<div id='item'>
|
2021-04-26 08:52:22 +00:00
|
|
|
<br/>
|
2021-08-15 21:28:37 +00:00
|
|
|
<ArrowBack className='backArrow' onClick={this.props.toggleFunction}/>
|
2021-04-26 08:52:22 +00:00
|
|
|
<br/>
|
|
|
|
<h1>{this.props.data.display_name}</h1>
|
|
|
|
{this.props.button}
|
2021-09-05 19:52:26 +00:00
|
|
|
{updateButton}
|
2021-07-15 14:08:37 +00:00
|
|
|
<br/><br/>
|
2021-05-03 10:27:52 +00:00
|
|
|
{iconsrc ? <img alt='product' draggable='false' src={iconsrc} onClick={() => this.setState({ showLightbox: true })}/> : null}
|
2021-07-15 14:08:37 +00:00
|
|
|
<div className='side'>
|
|
|
|
<div className='productInformation'>
|
|
|
|
<ul>
|
|
|
|
<li className='header'>{language.version}</li>
|
2021-09-05 19:52:26 +00:00
|
|
|
{updateButton ? <li>{this.props.data.version} (Installed: {this.props.data.addonInstalledVersion})</li> : <li>{this.props.data.version}</li>}
|
2021-07-15 14:08:37 +00:00
|
|
|
<br/>
|
|
|
|
<li className='header'>{language.author}</li>
|
|
|
|
<li>{this.props.data.author}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<br/>
|
|
|
|
{warningHTML}
|
|
|
|
</div>
|
2021-07-15 16:39:38 +00:00
|
|
|
<div className='sidebr'>
|
|
|
|
<br/><br/>
|
|
|
|
</div>
|
2021-04-26 08:52:22 +00:00
|
|
|
<div className='informationContainer'>
|
2021-05-24 10:43:38 +00:00
|
|
|
<h1 className='overview'>{language.overview}</h1>
|
2021-04-26 08:52:22 +00:00
|
|
|
<p className='description' dangerouslySetInnerHTML={{ __html: this.props.data.description }}></p>
|
|
|
|
</div>
|
2021-05-01 11:31:46 +00:00
|
|
|
<Modal closeTimeoutMS={100} onRequestClose={() => this.setState({ showLightbox: false })} isOpen={this.state.showLightbox} className='Modal lightboxmodal' overlayClassName='Overlay resetoverlay' ariaHideApp={false}>
|
2021-04-26 08:52:22 +00:00
|
|
|
<Lightbox modalClose={() => this.setState({ showLightbox: false })} img={iconsrc}/>
|
2021-05-01 11:31:46 +00:00
|
|
|
</Modal>
|
2020-08-26 13:32:52 +00:00
|
|
|
</div>
|
2021-04-26 08:52:22 +00:00
|
|
|
);
|
|
|
|
}
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|