source: phonelux-frontend/src/components/CompareOffersComponent/CompareOffersComponent.js@ 34950c6

Last change on this file since 34950c6 was d66b8eb, checked in by Marko <Marko@…>, 2 years ago

Component for editing offers added

  • Property mode set to 100644
File size: 7.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';
8
9export class CompareOffersComponent extends Component {
10
11 constructor(props) {
12 super(props)
13
14 this.state = {
15 offersToCompare: []
16 }
17 }
18 componentDidMount() {
19 if(localStorage.getItem('offersToCompare') && JSON.parse(localStorage.getItem('offersToCompare')).length >0)
20 {
21 let offersToCompareString = JSON.parse(localStorage.getItem('offersToCompare')).join(',')
22
23 var config = {
24 method: 'get',
25 url: '/multipleoffers?offerIds='+offersToCompareString,
26 headers: { }
27 };
28
29 axios(config)
30 .then(response => {
31 this.setState({
32 offersToCompare: response.data
33 })
34 })
35 .catch(error => {
36 console.log(error);
37 });
38 }
39 }
40
41 handleRemove = (event) => {
42 let offerToRemove = event.target.getAttribute('offerid')
43 let offers = JSON.parse(localStorage.getItem('offersToCompare'))
44 localStorage.setItem('offersToCompare',JSON.stringify(offers.filter(offer => offer!=offerToRemove)))
45 this.setState({
46 offersToCompare: this.state.offersToCompare.filter(offer => offer.id != offerToRemove)
47 })
48 }
49
50
51 render() {
52 console.log(this.state)
53 return (
54 <div className='compare-offers-main'>
55 <HeaderComponent/>
56 <div className='compare-offers-header'>
57 <h1 className='compare-offers-header-text'>
58 Спореди понуди
59 </h1>
60 </div>
61 {(() => {
62 if(localStorage.getItem('offersToCompare') && JSON.parse(localStorage.getItem('offersToCompare')).length >0)
63 {
64 return <table cellPadding={20} className='compare-offers-table'>
65 <tbody>
66 <tr className='compare-offers-table-row'>
67 <th className='compare-offer-table-headers'></th>
68 {
69 this.state.offersToCompare.map((offer,idx) =>
70 <Tippy placement='bottom' content='Отстранете ја понудата'>
71 <td onClick={this.handleRemove} className='compare-offers-top-headers' offerid={offer.id}
72 key={idx}>Понуда #{idx+1}</td>
73 </Tippy>
74 )
75 }
76 </tr>
77 <tr className='compare-offers-table-row'>
78 <th className='compare-offer-table-headers'>Име на понуда</th>
79 {
80 this.state.offersToCompare.map((offer,idx) => <td key={idx}><a href={offer.offer_url}>{offer.offer_name}</a></td>)
81 }
82 </tr>
83 <tr className='compare-offers-table-row'>
84 <th className='compare-offer-table-headers'>Продавница</th>
85 {
86 this.state.offersToCompare.map((offer,idx) => <td key={idx}><b>{offer.offer_shop}</b></td>)
87 }
88 </tr>
89 <tr className='compare-offers-table-row'>
90 <th className='compare-offer-table-headers'>Цена</th>
91 {
92 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.price}</td>)
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}>{offer.ram_memory == null ||
99 offer.ram_memory == '' ? '/' : offer.ram_memory}</td>)
100 }
101 </tr>
102 <tr className='compare-offers-table-row'>
103 <th className='compare-offer-table-headers'>РОМ меморија</th>
104 {
105 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.rom_memory == null ||
106 offer.rom_memory == '' ? '/' : offer.rom_memory}</td>)
107 }
108 </tr>
109 <tr className='compare-offers-table-row'>
110 <th className='compare-offer-table-headers'>Предна камера</th>
111 {
112 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.front_camera == null ||
113 offer.front_camera == '' ? '/' : offer.front_camera}</td>)
114 }
115 </tr>
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.back_camera == null ||
120 offer.back_camera == '' ? '/' : offer.back_camera}</td>)
121 }
122 </tr>
123 <tr className='compare-offers-table-row'>
124 <th className='compare-offer-table-headers'>Процесор</th>
125 {
126 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.cpu == null ||
127 offer.cpu == '' ? '/' : offer.cpu}</td>)
128 }
129 </tr>
130 <tr className='compare-offers-table-row'>
131 <th className='compare-offer-table-headers'>Чипсет</th>
132 {
133 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.chipset == null ||
134 offer.chipset == '' ? '/' : offer.chipset}</td>)
135 }
136 </tr>
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.operating_system == null ||
141 offer.operating_system == '' ? '/' : offer.operating_system}</td>)
142 }
143 </tr>
144 <tr className='compare-offers-table-row'>
145 <th className='compare-offer-table-headers'>Батерија</th>
146 {
147 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.battery == null ||
148 offer.battery == '' ? '/' : offer.battery}</td>)
149 }
150 </tr>
151 <tr className='compare-offers-table-row'>
152 <th className='compare-offer-table-headers'>Боја</th>
153 {
154 this.state.offersToCompare.map((offer,idx) => <td key={idx}>{offer.color == null ||
155 offer.color == '' ? '/' : offer.color}</td>)
156 }
157 </tr>
158 </tbody>
159 </table>
160 }
161 else{
162 return <h1 className='no-offers-saved-message'>Нема зачувано понуди</h1>
163 }
164
165 })()}
166
167 </div>
168 )
169 }
170}
171
172export default CompareOffersComponent
173
Note: See TracBrowser for help on using the repository browser.