import React, { Component } from 'react' import HeaderComponent from '../HeaderComponent/HeaderComponent' import './CompareOffersComponent.css' import CompareIcon from '@mui/icons-material/Compare'; import RemoveCircleIcon from '@mui/icons-material/RemoveCircle'; import axios from 'axios'; import Tippy from '@tippyjs/react'; export class CompareOffersComponent extends Component { constructor(props) { super(props) this.state = { offersToCompare: [] } } componentDidMount() { if(localStorage.getItem('offersToCompare') && JSON.parse(localStorage.getItem('offersToCompare')).length >0) { let offersToCompareString = JSON.parse(localStorage.getItem('offersToCompare')).join(',') var config = { method: 'get', url: '/multipleoffers?offerIds='+offersToCompareString, headers: { } }; axios(config) .then(response => { this.setState({ offersToCompare: response.data }) }) .catch(error => { console.log(error); }); } } handleRemove = (event) => { let offerToRemove = event.target.getAttribute('offerid') let offers = JSON.parse(localStorage.getItem('offersToCompare')) localStorage.setItem('offersToCompare',JSON.stringify(offers.filter(offer => offer!=offerToRemove))) this.setState({ offersToCompare: this.state.offersToCompare.filter(offer => offer.id != offerToRemove) }) } render() { console.log(this.state) return (

Спореди понуди

{(() => { if(localStorage.getItem('offersToCompare') && JSON.parse(localStorage.getItem('offersToCompare')).length >0) { return { this.state.offersToCompare.map((offer,idx) => ) } { this.state.offersToCompare.map((offer,idx) => ) } { this.state.offersToCompare.map((offer,idx) => ) } { this.state.offersToCompare.map((offer,idx) => ) } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РАМ меморија") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РОМ меморија") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Предна камера") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Задна камера") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Процесор") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Чипсет") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Оперативен систем") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Батерија") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> } { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Боја") ? { this.state.offersToCompare.map((offer,idx) => ) } : <> }
Понуда #{idx+1}
Име на понуда{offer.offer_name}
Продавница{offer.offer_shop}
Цена{offer.price} ден.
РАМ меморија{offer.ram_memory == null || offer.ram_memory == '' ? '/' : offer.ram_memory}
РОМ меморија{offer.rom_memory == null || offer.rom_memory == '' ? '/' : offer.rom_memory}
Предна камера{offer.front_camera == null || offer.front_camera == '' ? '/' : offer.front_camera}
Задна камера{offer.back_camera == null || offer.back_camera == '' ? '/' : offer.back_camera}
Процесор{offer.cpu == null || offer.cpu == '' ? '/' : offer.cpu}
Чипсет{offer.chipset == null || offer.chipset == '' ? '/' : offer.chipset}
Оперативен систем{offer.operating_system == null || offer.operating_system == '' ? '/' : offer.operating_system}
Батерија{offer.battery == null || offer.battery == '' ? '/' : offer.battery}
Боја{offer.color == null || offer.color == '' ? '/' : offer.color}
} else{ return

Нема зачувано понуди

} })()}
) } } export default CompareOffersComponent