This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
AllDestinations.jsx
92 lines (76 loc) · 2.81 KB
/
AllDestinations.jsx
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
import React, { Component } from "react";
import { Link } from "react-router-dom";
export default class AllDestinations extends Component {
constructor(props) {
super(props);
this.state = {
editing: {}
}
}
static defaultProps = {
destinations: [],
onDelete: () => null,
onEdit: () => null,
}
renderOrEditdestination = (destination) => {
const { editing } = this.state;
const editData = editing[destination.id];
const isEditing = !!editData;
const redStyle = {
color: 'red'
};
const blueStyle = {
color: 'blue'
};
var tempStyle ={
color: 'green'
};
if(destination.conditions.current > 80){
tempStyle = redStyle;
}
else if(destination.conditions.current < 65){
tempStyle = blueStyle;
}
return (
!isEditing ?
(
<Link to={`/destination/${destination.id}`} className="card" key={destination.id}>
<div className="content">
<div className="header">{destination.description}</div>
<div className="content">
<p><i className="icon calendar"></i>{(destination.id)}</p>
<p><i className="icon clock"></i>{(destination.conditions.description)}</p>
<p><i className="icon marker"></i><span style={tempStyle}>{destination.conditions.current} F</span></p>
</div>
</div>
</Link>
) : (
<tr key={destination.id}>
<td>
{destination.id}
</td>
<td>
<input type="text" value={editData.title} onChange={this.handleFieldEdit.bind(this, destination.id, 'description')} />
</td>
<td>
<button onClick={this.handleEditSave.bind(this, destination.id)}>Save</button>
<button onClick={this.handleEditCancel.bind(this, destination.id)}>Cancel</button>
</td>
</tr>
)
);
}
componentWillMount(){
this.props.subscribeToDestinations();
}
render() {
const { destinations } = this.props;
return (
<div>
<div className="ui link cards">
{[].concat(destinations).sort((a, b) => b.id - a.id).map(this.renderOrEditdestination)}
</div>
</div>
);
}
}