|
1 | | -import React from 'react'; |
2 | | -import axios from 'axios'; |
3 | | -import xml2js from 'xml2js'; |
4 | | -import './Medium.css'; |
| 1 | +import React from "react"; |
| 2 | +import axios from "axios"; |
| 3 | +import xml2js from "xml2js"; |
| 4 | +import "./Medium.css"; |
5 | 5 |
|
| 6 | +class Medium extends React.Component { |
| 7 | + state = { |
| 8 | + posts: [] |
| 9 | + }; |
6 | 10 |
|
7 | | -class Medium extends React.Component{ |
| 11 | + componentDidMount() { |
| 12 | + const mediumURL = "https://medium.com/feed/codeuino"; |
| 13 | + axios |
| 14 | + .get(`https://api.codetabs.com/v1/proxy?quest=${mediumURL}`) |
| 15 | + .then(res => { |
| 16 | + const data = res.data; |
| 17 | + xml2js.parseString(data, (err, result) => { |
| 18 | + this.setState({ |
| 19 | + posts: result.rss.channel[0].item.slice(0, 3) |
| 20 | + }); |
| 21 | + }); |
| 22 | + }); |
| 23 | + } |
8 | 24 |
|
9 | | - state = { |
10 | | - posts : [] |
11 | | - } |
12 | | - |
13 | | - componentDidMount(){ |
14 | | - const mediumURL = "https://medium.com/feed/codeuino"; |
15 | | - axios.get(`https://api.codetabs.com/v1/proxy?quest=${mediumURL}`) |
16 | | - .then((res) => { |
17 | | - const data = res.data; |
18 | | - xml2js.parseString(data, (err, result) => { |
19 | | - this.setState({ |
20 | | - posts: result.rss.channel[0].item.slice(0, 3) |
21 | | - }) |
22 | | - }); |
23 | | - }) |
24 | | - } |
25 | | - |
26 | | - render(){ |
27 | | - return( |
28 | | - <div |
29 | | - class="container" |
30 | | - style={{ width: "100%", alignContent: "left" }} |
31 | | - > |
32 | | - <h1 class="component-heading">Latest Blogs</h1> |
33 | | - <div class="row justify-content-center Medium" style={{ textAlign: "left" }}> |
34 | | - {this.state.posts.map((post, index) => ( |
35 | | - <div |
36 | | - className="col-md-4 Medium-post" |
37 | | - key={index} |
38 | | - dangerouslySetInnerHTML={{__html: post["content:encoded"][0]}}></div> |
39 | | - ))} |
| 25 | + render() { |
| 26 | + return ( |
| 27 | + <div class="container" style={{ width: "100%", alignContent: "left" }}> |
| 28 | + <h1 class="component-heading">Latest Blogs</h1> |
| 29 | + <div |
| 30 | + class="row justify-content-center Medium" |
| 31 | + style={{ textAlign: "left" }} |
| 32 | + > |
| 33 | + {this.state.posts.map((post, index) => ( |
| 34 | + <div className="col-md-4 Medium-post" key={index}> |
| 35 | + <a class="outer-link" href={post.link[0]}> |
| 36 | + <div |
| 37 | + dangerouslySetInnerHTML={{ |
| 38 | + __html: post["content:encoded"][0] |
| 39 | + }} |
| 40 | + ></div> |
| 41 | + <div className="fading-box"> |
| 42 | + <div className="view-more"> |
| 43 | + View More |
| 44 | + </div> |
40 | 45 | </div> |
| 46 | + </a> |
41 | 47 | </div> |
42 | | - |
43 | | - ); |
44 | | - } |
| 48 | + ))} |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + ); |
| 52 | + } |
45 | 53 | } |
46 | 54 |
|
47 | 55 | export default Medium; |
0 commit comments