source: phonelux-frontend/src/components/CompareOffersComponent/CompareOffersComponent.js

Last change on this file was fd5b100, checked in by Marko <Marko@…>, 21 months ago

Edited filter components

  • Property mode set to 100644
File size: 10.9 KB
Line 
1import React, { Component } from 'react'
2import HeaderComponent from '../HeaderComponent/HeaderComponent'
3import './CompareOffersComponent.css'
4import CompareIcon from '@mui/icons-material/Compare';
5import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
6import axios from 'axios';
7import Tippy from '@tippyjs/react';
8import VisibilityIcon from '@mui/icons-material/Visibility';
9import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
10
11export class CompareOffersComponent extends Component {
12
13 constructor(props) {
14 super(props)
15
16 this.state = {
17 offersToCompare: [],
18 showAllSpecs : false
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
53 changeShownSpecs = () => {
54 this.setState({
55 showAllSpecs: !this.state.showAllSpecs
56 })
57 }
58
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'>
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>
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 {
110 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.price} ден.</td>)
111 }
112 </tr>
113 { this.state.showAllSpecs ||
114 !localStorage.getItem('pickedSpecifications') ||
115 localStorage.getItem('pickedSpecifications').includes("РАМ меморија") ?
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 }
122 </tr> : <></>
123 }
124 { this.state.showAllSpecs ||
125 !localStorage.getItem('pickedSpecifications') ||
126 localStorage.getItem('pickedSpecifications').includes("РОМ меморија") ?
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 }
133 </tr> : <></>
134 }
135 { this.state.showAllSpecs ||
136 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Предна камера") ?
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 }
143 </tr> : <></>
144 }
145 { this.state.showAllSpecs ||
146 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Задна камера") ?
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 }
153 </tr> : <></>
154 }
155 { this.state.showAllSpecs ||
156 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Процесор") ?
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 }
163 </tr> : <></>
164 }
165 { this.state.showAllSpecs ||
166 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Чипсет") ?
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 }
173 </tr> : <></>
174 }
175 { this.state.showAllSpecs ||
176 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Оперативен систем") ?
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 }
183 </tr> : <></>
184 }
185 { this.state.showAllSpecs ||
186 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Батерија") ?
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 }
193 </tr> : <></>
194 }
195 { this.state.showAllSpecs ||
196 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Боја") ?
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 }
203 </tr> : <></>
204 }
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
219export default CompareOffersComponent
220
Note: See TracBrowser for help on using the repository browser.