|
1 | | -import React from 'react' |
2 | | -import PropTypes from 'prop-types' |
| 1 | +import React from 'react'; |
| 2 | +import './BlogList.css'; |
3 | 3 |
|
4 | | -export default function BlogList({title,content}) { |
5 | | - return ( |
6 | | - <> |
7 | | - <div class="mt-10"> |
8 | | - <main class="mt-5 pt-5"> |
9 | | - <div class="container"> |
| 4 | +class BlogList extends React.Component { |
| 5 | + constructor(props) { |
| 6 | + super(props); |
| 7 | + this.state = { |
| 8 | + activities: [], |
| 9 | + visible: false, |
| 10 | + currentActivity: null |
| 11 | + }; |
| 12 | + } |
10 | 13 |
|
11 | | - <section class="pt-5"> |
12 | | - <div class="wow fadeIn"> |
13 | | - <h2 class="h1 text-center mb-5">What is MDB?</h2> |
14 | | - <p class="text-center">MDB is world's most popular Material Design framework for building responsive, mobile-first websites |
15 | | - and apps. </p> |
16 | | - <p class="text-center mb-5 pb-5">Trusted by over |
17 | | - <strong>400 000</strong> developers and designers. Easy to use & customize. 400+ material UI elements, templates |
18 | | - & tutorials.</p> |
19 | | - </div> |
20 | | - <div class="row wow fadeIn"> |
21 | | - <div class="col-lg-5 col-xl-4 mb-4"> |
22 | | - <div class="view overlay rounded z-depth-1-half"> |
23 | | - <div class="view overlay"> |
24 | | - <div class="embed-responsive embed-responsive-16by9"> |
25 | | - <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/cXTThxoywNQ" allowfullscreen></iframe> |
26 | | - </div> |
27 | | - </div> |
28 | | - </div> |
29 | | - </div> |
30 | | - |
31 | | - </div> |
| 14 | + componentDidMount() { |
| 15 | + let activities = []; |
| 16 | + fetch('https://medium-article-fetcher.herokuapp.com/posts', { |
| 17 | + crossDomain: true, |
| 18 | + method: 'GET', |
| 19 | + headers: { 'Content-Type': 'application/json' } |
| 20 | + }) |
| 21 | + .then(res => { |
| 22 | + return res.json(); |
| 23 | + }) |
| 24 | + .then(resData => { |
| 25 | + for (let i = 0; i < resData.items.length; i++) { |
| 26 | + let obj = {}; |
| 27 | + obj.title = resData.items[i].title; |
| 28 | + obj.link = resData.items[i].link; |
| 29 | + let m, |
| 30 | + urls = [], |
| 31 | + str = resData.items[i].content_encoded, |
| 32 | + rex = /<img[^>]+src="?([^"\s]+)"?\s*\/>/g; |
32 | 33 |
|
33 | | - <hr class="mb-5"/> |
34 | | - <div class="row mt-3 wow fadeIn"> |
35 | | - <div class="col-lg-5 col-xl-4 mb-4"> |
36 | | - <div class="view overlay rounded z-depth-1"> |
37 | | - <img src="https://mdbootstrap.com/wp-content/uploads/2017/11/brandflow-tutorial-fb.jpg" class="img-fluid" alt=""/> |
38 | | - <a href="/#/blog" target="_blank"> |
39 | | - <div class="mask rgba-white-slight"></div> |
40 | | - </a> |
41 | | - </div> |
42 | | - </div> |
43 | | - <div class="col-lg-7 col-xl-7 ml-xl-4 mb-4"> |
44 | | - <h3 class="mb-3 font-weight-bold dark-grey-text"> |
45 | | - <strong>Bootstrap Automation</strong> |
46 | | - </h3> |
47 | | - <p class="grey-text">Learn how to create a smart website which learns your user and reacts properly to his behavior.</p> |
48 | | - <a href="/#/blog" class="btn btn-primary btn-md">Start tutorial |
49 | | - <i class="fas fa-play ml-2"></i> |
50 | | - </a> |
51 | | - </div> |
| 34 | + while ((m = rex.exec(str))) { |
| 35 | + urls.push(m[1]); |
| 36 | + } |
| 37 | + obj.img = urls[0]; |
52 | 38 |
|
53 | | - </div> |
| 39 | + let reg = /<\s*p[^>]*>([^<]*)<\s*\/\s*p\s*>/; |
| 40 | + let stream = resData.items[i].content_encoded.match(reg); |
54 | 41 |
|
55 | | - <hr class="mb-5"/> |
56 | | - <div class="row wow fadeIn"> |
57 | | - <div class="col-lg-5 col-xl-4 mb-4"> |
58 | | - <div class="view overlay rounded z-depth-1"> |
59 | | - <img src="https://mdbootstrap.com/wp-content/uploads/2018/01/push-fb.jpg" class="img-fluid" alt=""/> |
60 | | - <a href="/#/blog" target="_blank"> |
61 | | - <div class="mask rgba-white-slight"></div> |
62 | | - </a> |
63 | | - </div> |
64 | | - </div> |
65 | | - <div class="col-lg-7 col-xl-7 ml-xl-4 mb-4"> |
66 | | - <h3 class="mb-3 font-weight-bold dark-grey-text"> |
67 | | - <strong>Web Push notifications</strong> |
68 | | - </h3> |
69 | | - <p class="grey-text">Push messaging provides a simple and effective way to re-engage with your users and in this tutorial |
70 | | - you'll learn how to add push notifications to your web app</p> |
71 | | - <a href="/#/blog" target="_blank" class="btn btn-primary btn-md">Start tutorial |
72 | | - <i class="fas fa-play ml-2"></i> |
73 | | - </a> |
74 | | - </div> |
| 42 | + obj.description = |
| 43 | + stream[1] |
| 44 | + .split(' ') |
| 45 | + .slice(0, 20) |
| 46 | + .join(' ') + '...'; |
75 | 47 |
|
76 | | - </div> |
| 48 | + activities.push(obj); |
| 49 | + } |
| 50 | + this.setState({ activities: activities }); |
| 51 | + }) |
| 52 | + .catch(err => { |
| 53 | + console.log(err); |
| 54 | + }); |
| 55 | + } |
77 | 56 |
|
78 | | - <hr class="mb-5"/> |
79 | | - <nav class="d-flex justify-content-center wow fadeIn"> |
80 | | - <ul class="pagination pg-blue"> |
81 | | - <li class="page-item disabled"> |
82 | | - <a class="page-link" href="#" aria-label="Previous"> |
83 | | - <span aria-hidden="true">«</span> |
84 | | - <span class="sr-only">Previous</span> |
85 | | - </a> |
86 | | - </li> |
| 57 | + render() { |
| 58 | + return ( |
| 59 | + <div className='mt-10'> |
| 60 | + <main className='mt-5 pt-5'> |
| 61 | + <div className='container'> |
| 62 | + <section className='pt-5'> |
| 63 | + <div className='container-fluid d-flex space-between'> |
| 64 | + <div className='row'> |
| 65 | + {this.state.activities.map((currentActivity, index) => { |
| 66 | + return ( |
| 67 | + <div |
| 68 | + className='col-lg-4 col-md-6 col-sm-12' |
| 69 | + style={{ marginBottom: '20px' }} |
| 70 | + > |
| 71 | + <div className='card text-center activity overflow-hidden'> |
| 72 | + <img |
| 73 | + src={currentActivity.img} |
| 74 | + alt='' |
| 75 | + className='card-img-top activity' |
| 76 | + /> |
87 | 77 |
|
88 | | - <li class="page-item active"> |
89 | | - <a class="page-link" href="#">1 |
90 | | - <span class="sr-only">(current)</span> |
91 | | - </a> |
92 | | - </li> |
93 | | - <li class="page-item"> |
94 | | - <a class="page-link" href="#">2</a> |
95 | | - </li> |
96 | | - <li class="page-item"> |
97 | | - <a class="page-link" href="#">3</a> |
98 | | - </li> |
99 | | - <li class="page-item"> |
100 | | - <a class="page-link" href="#">4</a> |
101 | | - </li> |
102 | | - <li class="page-item"> |
103 | | - <a class="page-link" href="#">5</a> |
104 | | - </li> |
| 78 | + <div className='card-body text-dark flex-column d-flex'> |
| 79 | + <h4 className='card-title activity'> |
| 80 | + {currentActivity.title} |
| 81 | + </h4> |
| 82 | + <p className='card-text text-secondary'> |
| 83 | + {currentActivity.description} |
| 84 | + </p> |
105 | 85 |
|
106 | | - <li class="page-item"> |
107 | | - <a class="page-link" href="#" aria-label="Next"> |
108 | | - <span aria-hidden="true">»</span> |
109 | | - <span class="sr-only">Next</span> |
| 86 | + <a |
| 87 | + href={currentActivity.link} |
| 88 | + className='activity btn btn-outline-primary mt-auto btn-block align-self-end' |
| 89 | + style={{ marginTop: 'auto' }} |
| 90 | + > |
| 91 | + Read More |
110 | 92 | </a> |
111 | | - </li> |
112 | | - </ul> |
113 | | - </nav> |
114 | | - |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + ); |
| 97 | + })} |
| 98 | + </div> |
| 99 | + </div> |
115 | 100 | </section> |
116 | | - |
117 | | - </div> |
118 | | - </main> |
119 | | - </div> |
120 | | - </> |
121 | | - ); |
| 101 | + </div> |
| 102 | + </main> |
| 103 | + </div> |
| 104 | + ); |
| 105 | + } |
122 | 106 | } |
123 | 107 |
|
| 108 | +export default BlogList; |
0 commit comments