-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (91 loc) · 2.54 KB
/
index.js
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
import "bootstrap/dist/css/bootstrap.css";
import React, { useState } from "react";
import ReactDOM from "react-dom";
import Star from "./components/Star";
import { Grid, Row, Col, Button } from "react-bootstrap";
import Icon from "react-fa";
function Main(props) {
const [emails, updateEmails] = useState([
{
id: 0,
subject: "Big names using React.js today",
label: "star-o",
lastUpdated: new Date()
},
{
id: 1,
subject: "Lost in JavaScript and React tooling",
label: "star-o",
lastUpdated: new Date()
},
{
id: 2,
subject: "From Ruby to mobile through React.js?",
label: "star-o",
lastUpdated: new Date()
},
{
id: 3,
subject: "Browser Animations - icing on the cake",
label: "star-o",
lastUpdated: new Date()
},
{
id: 4,
subject:
"Ryanair Travel Itinerary - Don't Forget You Must Check-in Online and Print Off your Boarding Pass",
label: "plane",
lastUpdated: new Date()
},
{
id: 5,
subject: "Fifa admits scandal deters new sponsors",
label: "soccer-ball-o",
lastUpdated: new Date()
}
]);
function onLabelChange(id, newLabel) {
const newEmails = [...emails];
newEmails[id].label = newLabel;
newEmails[id].lastUpdated = new Date();
updateEmails(newEmails);
}
function onRandomLabelAssign(id, reactEvent) {
const newEmails = [...emails];
newEmails[id].label = ["check", "question-circle", "exclamation-triangle"][
Date.now() % 3
];
newEmails[id].lastUpdated = new Date();
updateEmails(newEmails);
}
return (
<Grid>
{emails.map(email =>
<Row key={`row-${email.id}`}>
<Col md={1}>
<Star
label={email.label}
onChange={onLabelChange.bind(null, email.id)}
/>
</Col>
<Col md={10}>
{email.subject}
<div className="timestamp">
{email.lastUpdated.toISOString()}
</div>
</Col>
<Col md={1}>
<Button
bsSize="large"
bsStyle="link"
onClick={onRandomLabelAssign.bind(null, email.id)}
>
<Icon name="random" />
</Button>
</Col>
</Row>
)}
</Grid>
);
}
ReactDOM.render(<Main />, document.getElementById("root"));