Skip to content

Commit a753343

Browse files
author
Saulo Benigno
committed
api to get media type and logo
1 parent 2de3b5f commit a753343

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

.idea/workspace.xml

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/data/social_types.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"Symbol": "FBOK34",
4+
"Media": "Facebook Inc.",
5+
"Type": "Facebook",
6+
"Img": "./images/facebook.png"
7+
},
8+
{
9+
"Symbol": "GOGL34",
10+
"Media": "Alphabet Inc.",
11+
"Type": "Google",
12+
"Img": "./images/google.png"
13+
},
14+
{
15+
"Symbol": "TWTR34",
16+
"Media": "Twitter, Inc.",
17+
"Type": "Twitter",
18+
"Img": "./images/twitter.png"
19+
},
20+
{
21+
"Symbol": "P2IN34",
22+
"Media": "Pinterest, Inc.",
23+
"Type": "Pinterest",
24+
"Img": "./images/pinterest.png"
25+
}
26+
]

src/components/Table.jsx

+21-18
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,42 @@ export default class Table extends React.Component {
55

66
state = {
77
dates: [],
8+
social_types: []
89
}
910

1011
componentDidMount() {
12+
1113
api.get("./data/dates.json")
1214
.then((response) => {
1315
this.setState({dates: response.data})
1416
} )
1517
.catch((err) => {
1618
console.error("ops! error: " + err);
1719
});
20+
21+
api.get("./data/social_types.json")
22+
.then((response) => {
23+
this.setState({social_types: response.data})
24+
} )
25+
.catch((err) => {
26+
console.error("ops! error: " + err);
27+
});
28+
29+
1830
}
1931

32+
2033
render() {
2134

22-
let social_media = [];
23-
let social_type;
35+
let { social_types } = this.state
36+
social_types = (social_types.filter(social => social.Symbol.includes(this.props.symbol)));
37+
38+
let social_media = social_types.map(function (img) { return img['Media']; });
39+
let social_type = social_types.map(function (img) { return img['Type']; });
40+
let social_logo = social_types.map(function (img) { return img['Img']; });
2441
let prices = [];
2542
let counts = [];
2643

27-
if (this.props.symbol === 'FBOK34') {
28-
social_media = 'Facebook Inc.';
29-
social_type = 'Facebook';
30-
} else if (this.props.symbol === 'GOGL34') {
31-
social_media = 'Alphabet Inc.';
32-
social_type = 'Google';
33-
} else if (this.props.symbol === 'TWTR34') {
34-
social_media = 'Twitter, Inc.';
35-
social_type = 'Twitter';
36-
} else if (this.props.symbol === 'P2IN34') {
37-
social_media = 'Pinterest, Inc.';
38-
social_type = 'Pinterest';
39-
}
40-
4144
function randomDate(start, end) {
4245
start = new Date(2020, 1, 1);
4346
end = new Date();
@@ -104,7 +107,7 @@ export default class Table extends React.Component {
104107
<tr key={i}>
105108
<td className="index">{i+1}</td>
106109
<td>
107-
{social_media}
110+
<img src={social_logo} width="24" alt={social_media + ' logo'} title={social_media} /> {social_media}
108111
</td>
109112
<td>
110113
{this.props.symbol}
@@ -113,7 +116,7 @@ export default class Table extends React.Component {
113116
{date.date}
114117
</td>
115118
<td>
116-
{prices[i].stock_price}
119+
$ {prices[i].stock_price}
117120
</td>
118121
<td>
119122
{counts[i].media_count}

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import App from './App';
44

5-
ReactDOM.render(<App/>, document.getElementById('root'));
5+
ReactDOM.render(<React.StrictMode><App/></React.StrictMode>, document.getElementById('root'));

src/services/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from "axios";
22

33
const api = axios.create({
4-
baseURL: '/',
4+
baseURL: '/'
55
});
66

77
export default api;

0 commit comments

Comments
 (0)