-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty.js
More file actions
328 lines (306 loc) · 12.4 KB
/
property.js
File metadata and controls
328 lines (306 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import React from 'react';
import './index.css';
class PropertyList extends React.Component{
constructor(props) {
super(props);
this.state = {
totalCount: 0,
data: [],
dataDeepCopy: [],
activeView: 'listView',
minRent: 0,
maxRent: 0,
minSize: 0,
maxSize: 0,
popupVisible: false,
filterPopup: true,
width: window.innerWidth,
shortlisted: []
};
this.handleSort = this.handleSort.bind(this);
this.handleChange = this.handleChange.bind(this);
this.filterContentPrice = this.filterContentPrice.bind(this)
}
componentWillMount() {
window.addEventListener('resize', this.handleWindowSizeChange);
}
componentDidMount() {
fetch("https://demo8808386.mockable.io/fetchProperties")
.then(res => res.json())
.then(
(result) => {
console.log(result.data)
this.setState({ data: result.data})
var dataCopy = JSON.parse(JSON.stringify(this.state.data));
var totalCount = this.state.data.length
this.setState({totalCount: totalCount})
this.setState({dataDeepCopy: dataCopy})
this.findMinMax(this.state.data);
},
(error) => {
}
)
this.togglePopup(false)
}
componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowSizeChange);
}
handleWindowSizeChange = () => {
this.setState({ width: window.innerWidth });
};
changeView(e){
var element = e.target;
if(element.classList.contains('gridView')){
this.setState({activeView: 'gridView'});
}else{
this.setState({activeView: 'listView'});
}
}
handleChange(e) {
var element = e.target;
if(element.name == "rent"){
this.setState({minRent: element.value});
console.log(this.state.minRent)
this.filterContentPrice(this.state.minRent)
}else{
this.setState({minSize: element.value});
this.filterContentSize(this.state.minSize)
}
}
filterContentPrice(value){
const dataCopy = this.state.dataDeepCopy
const filteredData = dataCopy.filter((item) =>
item.rent > value);
this.setState({data: filteredData})
}
filterContentSize(value){
const dataCopy = this.state.dataDeepCopy
const filteredData = dataCopy.filter((item) =>
item.propertySize > value);
this.setState({data: filteredData})
}
findMinMax(dataList){
var lowestRent = Number.POSITIVE_INFINITY;
var highestRent = Number.NEGATIVE_INFINITY;
var minSize = Number.POSITIVE_INFINITY;
var maxSize = Number.NEGATIVE_INFINITY;
var tmp;
for (let i= dataList.length-1; i>=0; i--) {
tmp = dataList[i].rent;
if (tmp < lowestRent) lowestRent = tmp;
if (tmp > highestRent) highestRent = tmp;
}
this.setState({minRent: lowestRent})
this.setState({maxRent: highestRent})
for (let i= dataList.length-1; i>=0; i--) {
tmp = dataList[i].propertySize;
if (tmp < minSize) minSize = tmp;
if (tmp > maxSize) maxSize = tmp;
}
this.setState({minSize: minSize})
this.setState({maxSize: maxSize})
}
capitalize(str){
return str.charAt(0).toUpperCase() + str.slice(1);
}
shortlistProperty(e,value){
console.log("+++++++++"+value)
var element = e.target
var dataList = this.state.data
console.log(dataList[value])
this.setState({shortlisted: this.state.data[value]})
console.log(this.state.shortlisted)
}
renderPropertyList(items){
var propertyListItem = items.map((item, i) => {
return (
<div key={i} className={this.state.activeView == 'listView' ? 'propertyListItem' : 'propertyGridItem'}>
{this.state.activeView == "listView" ?
<div className="itemBlock">
<div className="itemImage">
{item.photos.length ? this.showImages(item.photos) : <img src="https://images.nobroker.in/static/img/resale/1bhk.jpg"/>}
<div className="price">₹ {item.rent} /-</div>
</div>
<div className="itemDescription">
<p className="itemTitle truncate">{item.propertyTitle}</p>
<p className="truncate"><span></span><span className="itemStreet">{item.street}</span><span className="dotSeperator"> . </span><span className="itemLocality"> {item.locality}</span></p>
<p className="itemInfo"> {item.propertySize} sq.ft | Built {item.propertyAge == 0 ? 'this year' : item.propertyAge+' years ago'} | {item.floor == 0 ? 'Ground': item.floor } floor | {this.capitalize(item.furnishing)} {item.leaseType == 'FAMILY'? " | Family only":''}</p>
<p>₹ {item.deposit} Deposit</p>
<p>Posted on {this.getDate(item.creationDate)}</p>
<p>Available from {this.getDate(item.availableFrom)}</p>
<p className="lastUpdateDate">Last updated on {this.getDate(item.lastUpdateDate)}</p>
</div>
<div className="listItemShortlist pointer">
<p className="shortListImage" onClick={this.shortlistProperty.bind(this,i)}></p>
</div>
</div>
:
<div className="gridItemBlock">
<div className="itemImage">
{item.photos.length ? this.showImages(item.photos) : <img src="https://images.nobroker.in/static/img/resale/1bhk.jpg" />}
<div className="price">₹ {item.rent} /-</div>
</div>
<div className="itemDescription">
<p className="itemTitle truncate">{item.propertyTitle}</p>
<p className="truncate"><span className=""></span><span className="itemStreet">{item.street}</span><span className="dotSeperator"> . </span><span className="itemLocality"> {item.locality}</span></p>
<p> {item.propertySize} sq.ft | {item.floor == 0 ? 'Ground': item.floor } floor</p>
<p>₹ {item.deposit} Deposit</p>
{item.amenitiesMap.length ? <p>Amenities : {this.renderAmenities(item.amenitiesMap)}</p>: ''}
<p className="lastUpdateDate">Last updated on {this.getDate(item.lastUpdateDate)}</p>
</div>
<div className="shortListBlock pointer">
<p className="shortListImage" onClick={this.shortlistProperty.bind(this,i)}></p>
</div>
</div>
}
</div>
);
});
return propertyListItem;
}
renderAmenities(amenitieItem){
var amenitieList = Object.keys(amenitieItem).map(function(keyName, keyIndex) {
return (
<span key={keyName} className="">
{amenitieItem[keyName] ? keyName+', ' : ''}
</span>
);
});
return amenitieList;
}
getDate(date){
var months_arr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var date = new Date(date);
var year = date.getFullYear();
var month = months_arr[date.getMonth()];
var day = date.getDate();
var updateDate = month+'-'+day+'-'+year;
return updateDate
}
showImages(images){
var propertyImage;
images.map((item, i) => {
propertyImage = Object.keys(item.imagesMap).map(function(keyName, keyIndex) {
if(keyName == 'medium'){
var url = item.imagesMap[keyName]
var imagePath = item.imagesMap[keyName].split('_')
return (
<img key={keyName} src={"https://assets.nobroker.in/images/"+imagePath[0]+"/"+url} />
);
}
});
})
return propertyImage;
}
handleSort(e){
var element = e.target;
var value = e.target.value
var dataCopy = this.state.data
if(value == "priceLowToHigh"){
let sortedData = dataCopy.sort((a, b) => a.rent - b.rent)
this.setState({ data: sortedData})
}else if(value == "priceHighToLow"){
let sortedData = dataCopy.sort((a, b) => a.rent - b.rent).reverse()
this.setState({ data: sortedData})
}else if(value == "Newest"){
let sortedData = dataCopy.sort((a, b) => a.propertyAge - b.propertyAge)
this.setState({ data: sortedData })
}else if(value == "creationDate"){
let sortedData = dataCopy.sort((a, b) => a.creationDate - b.creationDate).reverse()
this.setState({ data: sortedData })
}
}
togglePopup(value){
const { width } = this.state;
const isMobile = width <= 500;
if(isMobile){
this.setState({filterPopup: value})
}
}
render(){
const { width } = this.state;
const isMobile = width <= 500;
return (
<div className="background">
<header className="header">
<div className="displayFlexHeader">
<p className="headerName">SHELTER</p>
<p className="loginInfo">
<span className="mr-20 pointer">Piyush Kumar</span>
<span className="pointer">Log out</span>
</p>
</div>
</header>
<div className="mainContent">
{this.state.filterPopup == true &&
<div className="fixedLeft">
<span className="floatRight pointer smallOnly" onClick={this.togglePopup.bind(this,false)}>X</span>
<p className="paddingTB16 bold">Filter</p>
<div className="filterBlock">
<div className="borderInBox">
<div className="slidecontainer">
<p className="filterTitle">Rent: {this.state.currentRent}<span id="demo"></span></p>
<input type="range" min="0" max={this.state.maxRent} value={this.state.minRent} name="rent" className="slider" onChange={this.handleChange.bind(this)} step="100"/>
<p className="filterInfo"><span>₹ {this.state.minRent}</span><span>₹ {this.state.maxRent}</span></p>
</div>
<div className="slidecontainer">
<p className="filterTitle">Property Size: {this.state.currentSize}<span id="demo"></span></p>
<input type="range" min="0" max={this.state.maxSize} value={this.state.minSize} name="size" className="slider" step="100" onChange={this.handleChange.bind(this)} />
<p className="filterInfo"><span>{this.state.minSize} sq.ft</span><span>{this.state.maxSize} sq.ft</span></p>
</div>
</div>
</div>
<p className="paddingTB16 bold">Sort</p>
<div className="filterBlock">
<div className="borderInBox">
<p className="clear-fix">
<label className="lablDiv greenRadioContainer alignRadioLeft display-IB">
<span className="labelText"> Price(Low to High) </span>
<input type="radio" className="dis-none" value="priceLowToHigh" name="sort" onClick={this.handleSort.bind(this)} />
<span className="floatLeft mt-1"></span>
</label>
</p>
<p className="clear-fix">
<label className="lablDiv greenRadioContainer alignRadioLeft display-IB">
<span className="labelText"> Price(High to Low) </span>
<input type="radio" className="dis-none" value="priceHighToLow" name="sort" onClick={this.handleSort.bind(this)}/>
<span className="floatLeft mt-1"></span>
</label>
</p>
<p className="clear-fix">
<label className="lablDiv greenRadioContainer alignRadioLeft display-IB">
<span className="labelText"> Creation Date </span>
<input type="radio" className="dis-none" value="creationDate" name="sort" onClick={this.handleSort.bind(this)}/>
<span className="floatLeft mt-1"></span>
</label>
</p>
<p className="clear-fix">
<label className="lablDiv greenRadioContainer alignRadioLeft display-IB">
<span className="labelText"> Property Age </span>
<input type="radio" className="dis-none" value="Newest" name="sort" onClick={this.handleSort.bind(this)}/>
<span className="floatLeft mt-1"></span>
</label>
</p>
</div>
</div>
</div>
}
<div className="rightBlock">
<div className="paddingTB10 viewHolder">
<p className="smallOnly mobileFilter pointer" onClick={this.togglePopup.bind(this,true)}>Filter</p>
<p className="smallOnly mobileFilter mr-12 pointer" onClick={this.togglePopup.bind(this,true)}>Sort</p>
<p className={"listView pointer" + (this.state.activeView == 'gridView' ? " opacity" :'')} onClick={this.changeView.bind(this)}></p>
<p className={"gridView pointer" + (this.state.activeView == 'listView' ? " opacity" :'')} onClick={this.changeView.bind(this)}></p>
</div>
<div className={this.state.activeView == 'listView' ? 'propertyList' : 'propertyGrid'}>
{this.renderPropertyList(this.state.data)}
</div>
</div>
</div>
<footer>
</footer>
</div>
);
}
}
export default PropertyList;