[d66b8eb] | 1 | import React, { Component } from 'react'
|
---|
| 2 | import HeaderComponent from '../HeaderComponent/HeaderComponent'
|
---|
| 3 | import './CompareOffersComponent.css'
|
---|
| 4 | import CompareIcon from '@mui/icons-material/Compare';
|
---|
| 5 | import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
|
---|
| 6 | import axios from 'axios';
|
---|
| 7 | import Tippy from '@tippyjs/react';
|
---|
[fd5b100] | 8 | import VisibilityIcon from '@mui/icons-material/Visibility';
|
---|
| 9 | import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
---|
[d66b8eb] | 10 |
|
---|
| 11 | export class CompareOffersComponent extends Component {
|
---|
| 12 |
|
---|
| 13 | constructor(props) {
|
---|
| 14 | super(props)
|
---|
| 15 |
|
---|
| 16 | this.state = {
|
---|
[fd5b100] | 17 | offersToCompare: [],
|
---|
| 18 | showAllSpecs : false
|
---|
[d66b8eb] | 19 | }
|
---|
| 20 | }
|
---|
| 21 | componentDidMount() {
|
---|
| 22 | if(localStorage.getItem('offersToCompare') && JSON.parse(localStorage.getItem('offersToCompare')).length >0)
|
---|
| 23 | {
|
---|
| 24 | let offersToCompareString = JSON.parse(localStorage.getItem('offersToCompare')).join(',')
|
---|
| 25 |
|
---|
| 26 | var config = {
|
---|
| 27 | method: 'get',
|
---|
| 28 | url: '/multipleoffers?offerIds='+offersToCompareString,
|
---|
| 29 | headers: { }
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | axios(config)
|
---|
| 33 | .then(response => {
|
---|
| 34 | this.setState({
|
---|
| 35 | offersToCompare: response.data
|
---|
| 36 | })
|
---|
| 37 | })
|
---|
| 38 | .catch(error => {
|
---|
| 39 | console.log(error);
|
---|
| 40 | });
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | handleRemove = (event) => {
|
---|
| 45 | let offerToRemove = event.target.getAttribute('offerid')
|
---|
| 46 | let offers = JSON.parse(localStorage.getItem('offersToCompare'))
|
---|
| 47 | localStorage.setItem('offersToCompare',JSON.stringify(offers.filter(offer => offer!=offerToRemove)))
|
---|
| 48 | this.setState({
|
---|
| 49 | offersToCompare: this.state.offersToCompare.filter(offer => offer.id != offerToRemove)
|
---|
| 50 | })
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[fd5b100] | 53 | changeShownSpecs = () => {
|
---|
| 54 | this.setState({
|
---|
| 55 | showAllSpecs: !this.state.showAllSpecs
|
---|
| 56 | })
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[d66b8eb] | 59 |
|
---|
| 60 | render() {
|
---|
| 61 | return (
|
---|
| 62 | <div className='compare-offers-main'>
|
---|
| 63 | <HeaderComponent/>
|
---|
| 64 | <div className='compare-offers-header'>
|
---|
| 65 | <h1 className='compare-offers-header-text'>
|
---|
| 66 | Спореди понуди
|
---|
| 67 | </h1>
|
---|
| 68 | </div>
|
---|
| 69 | {(() => {
|
---|
| 70 | if(localStorage.getItem('offersToCompare') && JSON.parse(localStorage.getItem('offersToCompare')).length >0)
|
---|
| 71 | {
|
---|
| 72 | return <table cellPadding={20} className='compare-offers-table'>
|
---|
| 73 | <tbody>
|
---|
| 74 | <tr className='compare-offers-table-row'>
|
---|
[fd5b100] | 75 | <th className='compare-offer-table-headers'>
|
---|
| 76 | {
|
---|
| 77 | this.state.showAllSpecs ?
|
---|
| 78 | <Tippy placement='bottom' content='Прикажи ги избраните спецификации'>
|
---|
| 79 | <VisibilityOffIcon className='show-all-specs-icon' onClick={this.changeShownSpecs} style={{fontSize: '45px'}}/>
|
---|
| 80 | </Tippy> :
|
---|
| 81 | <Tippy placement='bottom' content='Прикажи ги сите спецификации'>
|
---|
| 82 | <VisibilityIcon className='show-all-specs-icon' onClick={this.changeShownSpecs} style={{fontSize: '45px'}}/>
|
---|
| 83 | </Tippy>
|
---|
| 84 | }
|
---|
| 85 | </th>
|
---|
[d66b8eb] | 86 | {
|
---|
| 87 | this.state.offersToCompare.map((offer,idx) =>
|
---|
| 88 | <Tippy placement='bottom' content='Отстранете ја понудата'>
|
---|
| 89 | <td onClick={this.handleRemove} className='compare-offers-top-headers' offerid={offer.id}
|
---|
| 90 | key={idx}>Понуда #{idx+1}</td>
|
---|
| 91 | </Tippy>
|
---|
| 92 | )
|
---|
| 93 | }
|
---|
| 94 | </tr>
|
---|
| 95 | <tr className='compare-offers-table-row'>
|
---|
| 96 | <th className='compare-offer-table-headers'>Име на понуда</th>
|
---|
| 97 | {
|
---|
| 98 | this.state.offersToCompare.map((offer,idx) => <td key={idx}><a href={offer.offer_url}>{offer.offer_name}</a></td>)
|
---|
| 99 | }
|
---|
| 100 | </tr>
|
---|
| 101 | <tr className='compare-offers-table-row'>
|
---|
| 102 | <th className='compare-offer-table-headers'>Продавница</th>
|
---|
| 103 | {
|
---|
| 104 | this.state.offersToCompare.map((offer,idx) => <td key={idx}><b>{offer.offer_shop}</b></td>)
|
---|
| 105 | }
|
---|
| 106 | </tr>
|
---|
| 107 | <tr className='compare-offers-table-row'>
|
---|
| 108 | <th className='compare-offer-table-headers'>Цена</th>
|
---|
| 109 | {
|
---|
[48f3030] | 110 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.price} ден.</td>)
|
---|
[d66b8eb] | 111 | }
|
---|
| 112 | </tr>
|
---|
[fd5b100] | 113 | { this.state.showAllSpecs ||
|
---|
| 114 | !localStorage.getItem('pickedSpecifications') ||
|
---|
| 115 | localStorage.getItem('pickedSpecifications').includes("РАМ меморија") ?
|
---|
[d66b8eb] | 116 | <tr className='compare-offers-table-row'>
|
---|
| 117 | <th className='compare-offer-table-headers'>РАМ меморија</th>
|
---|
| 118 | {
|
---|
| 119 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.ram_memory == null ||
|
---|
| 120 | offer.ram_memory == '' ? '/' : offer.ram_memory}</td>)
|
---|
| 121 | }
|
---|
[48f3030] | 122 | </tr> : <></>
|
---|
| 123 | }
|
---|
[fd5b100] | 124 | { this.state.showAllSpecs ||
|
---|
| 125 | !localStorage.getItem('pickedSpecifications') ||
|
---|
| 126 | localStorage.getItem('pickedSpecifications').includes("РОМ меморија") ?
|
---|
[d66b8eb] | 127 | <tr className='compare-offers-table-row'>
|
---|
| 128 | <th className='compare-offer-table-headers'>РОМ меморија</th>
|
---|
| 129 | {
|
---|
| 130 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.rom_memory == null ||
|
---|
| 131 | offer.rom_memory == '' ? '/' : offer.rom_memory}</td>)
|
---|
| 132 | }
|
---|
[48f3030] | 133 | </tr> : <></>
|
---|
| 134 | }
|
---|
[fd5b100] | 135 | { this.state.showAllSpecs ||
|
---|
| 136 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Предна камера") ?
|
---|
[d66b8eb] | 137 | <tr className='compare-offers-table-row'>
|
---|
| 138 | <th className='compare-offer-table-headers'>Предна камера</th>
|
---|
| 139 | {
|
---|
| 140 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.front_camera == null ||
|
---|
| 141 | offer.front_camera == '' ? '/' : offer.front_camera}</td>)
|
---|
| 142 | }
|
---|
[48f3030] | 143 | </tr> : <></>
|
---|
| 144 | }
|
---|
[fd5b100] | 145 | { this.state.showAllSpecs ||
|
---|
| 146 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Задна камера") ?
|
---|
[d66b8eb] | 147 | <tr className='compare-offers-table-row'>
|
---|
| 148 | <th className='compare-offer-table-headers'>Задна камера</th>
|
---|
| 149 | {
|
---|
| 150 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.back_camera == null ||
|
---|
| 151 | offer.back_camera == '' ? '/' : offer.back_camera}</td>)
|
---|
| 152 | }
|
---|
[48f3030] | 153 | </tr> : <></>
|
---|
| 154 | }
|
---|
[fd5b100] | 155 | { this.state.showAllSpecs ||
|
---|
| 156 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Процесор") ?
|
---|
[d66b8eb] | 157 | <tr className='compare-offers-table-row'>
|
---|
| 158 | <th className='compare-offer-table-headers'>Процесор</th>
|
---|
| 159 | {
|
---|
| 160 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.cpu == null ||
|
---|
| 161 | offer.cpu == '' ? '/' : offer.cpu}</td>)
|
---|
| 162 | }
|
---|
[48f3030] | 163 | </tr> : <></>
|
---|
| 164 | }
|
---|
[fd5b100] | 165 | { this.state.showAllSpecs ||
|
---|
| 166 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Чипсет") ?
|
---|
[d66b8eb] | 167 | <tr className='compare-offers-table-row'>
|
---|
| 168 | <th className='compare-offer-table-headers'>Чипсет</th>
|
---|
| 169 | {
|
---|
| 170 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.chipset == null ||
|
---|
| 171 | offer.chipset == '' ? '/' : offer.chipset}</td>)
|
---|
| 172 | }
|
---|
[48f3030] | 173 | </tr> : <></>
|
---|
| 174 | }
|
---|
[fd5b100] | 175 | { this.state.showAllSpecs ||
|
---|
| 176 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Оперативен систем") ?
|
---|
[d66b8eb] | 177 | <tr className='compare-offers-table-row'>
|
---|
| 178 | <th className='compare-offer-table-headers'>Оперативен систем</th>
|
---|
| 179 | {
|
---|
| 180 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.operating_system == null ||
|
---|
| 181 | offer.operating_system == '' ? '/' : offer.operating_system}</td>)
|
---|
| 182 | }
|
---|
[48f3030] | 183 | </tr> : <></>
|
---|
| 184 | }
|
---|
[fd5b100] | 185 | { this.state.showAllSpecs ||
|
---|
| 186 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Батерија") ?
|
---|
[d66b8eb] | 187 | <tr className='compare-offers-table-row'>
|
---|
| 188 | <th className='compare-offer-table-headers'>Батерија</th>
|
---|
| 189 | {
|
---|
| 190 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.battery == null ||
|
---|
| 191 | offer.battery == '' ? '/' : offer.battery}</td>)
|
---|
| 192 | }
|
---|
[48f3030] | 193 | </tr> : <></>
|
---|
| 194 | }
|
---|
[fd5b100] | 195 | { this.state.showAllSpecs ||
|
---|
| 196 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Боја") ?
|
---|
[d66b8eb] | 197 | <tr className='compare-offers-table-row'>
|
---|
| 198 | <th className='compare-offer-table-headers'>Боја</th>
|
---|
| 199 | {
|
---|
| 200 | this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.color == null ||
|
---|
| 201 | offer.color == '' ? '/' : offer.color}</td>)
|
---|
| 202 | }
|
---|
[48f3030] | 203 | </tr> : <></>
|
---|
| 204 | }
|
---|
[d66b8eb] | 205 | </tbody>
|
---|
| 206 | </table>
|
---|
| 207 | }
|
---|
| 208 | else{
|
---|
| 209 | return <h1 className='no-offers-saved-message'>Нема зачувано понуди</h1>
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | })()}
|
---|
| 213 |
|
---|
| 214 | </div>
|
---|
| 215 | )
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | export default CompareOffersComponent
|
---|
| 220 |
|
---|