-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquote.jsx
More file actions
52 lines (46 loc) · 1.71 KB
/
quote.jsx
File metadata and controls
52 lines (46 loc) · 1.71 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
const quoteData = [
{ text: "The only way to do great work is to love what you do.", author: "Steve Jobs" },
{ text: "Life is what happens when you're busy making other plans.", author: "John Lennon" },
{ text: "The future belongs to those who believe in the beauty of their dreams.", author: "Eleanor Roosevelt" },
{ text: "Strive not to be a success, but rather to be of value.", author: "Albert Einstein" },
{ text: "The only impossible journey is the one you never begin.", author: "Tony Robbins" }
];
class QuoteMachine extends React.Component {
constructor(props) {
super(props);
this.state = {
quote: quoteData[0]
};
this.getNewQuote = this.getNewQuote.bind(this);
}
componentDidMount() {
this.getNewQuote();
}
getNewQuote() {
const randomIndex = Math.floor(Math.random() * quoteData.length);
this.setState({
quote: quoteData[randomIndex]
});
}
render() {
const { quote } = this.state;
const tweetUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(`"${quote.text}" - ${quote.author}`)}`;
return (
<div id="quote-box">
<div className="quote-content">
<i className="fas fa-quote-left"></i>
<p id="text">{quote.text}</p>
<i className="fas fa-quote-right"></i>
</div>
<p id="author">- {quote.author}</p>
<div className="buttons">
<button id="new-quote" onClick={this.getNewQuote}>New Quote</button>
<a id="tweet-quote" href={tweetUrl} target="_blank" rel="noopener noreferrer">
<i className="fab fa-twitter"></i> Tweet
</a>
</div>
</div>
);
}
}
ReactDOM.render(<QuoteMachine />, document.getElementById('root'));