Skip to content

Commit 17bfc7b

Browse files
committed
Added the main component
1 parent c0182c0 commit 17bfc7b

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed

news-app/src/Components/Main.css

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
.main {
2+
background-color: rgb(252, 252, 252);
3+
}
4+
5+
.tesla-main {
6+
max-width: 1250px;
7+
margin: 0 auto;
8+
}
9+
10+
.main-heading {
11+
padding: 30px 0;
12+
font-size: 26px;
13+
color: #111;
14+
}
15+
16+
.card-container {
17+
display: flex;
18+
flex-wrap: wrap;
19+
max-width: 1250px;
20+
margin: 0 auto;
21+
justify-content: space-between;
22+
}
23+
24+
.tesla-container {
25+
display: flex;
26+
overflow-x: scroll;
27+
overflow-y: hidden;
28+
padding: 20px;
29+
margin: 30px 0;
30+
}
31+
32+
.tesla-heading {
33+
border-bottom: 1px solid rgb(214, 214, 214);
34+
padding-bottom: 30px;
35+
}
36+
37+
.tesla-container::-webkit-scrollbar {
38+
display: none;
39+
}
40+
41+
.card {
42+
width: 370px;
43+
height: 420px;
44+
background-color: #fff;
45+
box-shadow: 2px 3px 9px rgba(0, 0, 0, 0.8);
46+
margin-bottom: 70px;
47+
overflow: hidden;
48+
transition: all 0.5s;
49+
}
50+
51+
.card:hover {
52+
transform: scale(0.9);
53+
}
54+
55+
.card1 {
56+
width: 500px;
57+
height: 100px;
58+
display: flex;
59+
align-items: center;
60+
}
61+
62+
.card1 .image {
63+
width: 140px;
64+
height: 100px;
65+
transition: all 0.5s;
66+
}
67+
68+
.card1 .image:hover {
69+
transform: scale(1.15);
70+
}
71+
72+
.info {
73+
width:360px;
74+
height: 90px;
75+
overflow: hidden;
76+
padding-left: 20px;
77+
text-align: left;
78+
padding-right: 30px;
79+
}
80+
81+
.info h3 {
82+
font-size: 19px;
83+
font-weight: 300;
84+
height: 50px;
85+
overflow: hidden;
86+
padding-bottom: 10px;
87+
}
88+
89+
.info p {
90+
font-size: 13px;
91+
height: 50px;
92+
overflow: hidden;
93+
color: gray;
94+
}
95+
96+
.image img {
97+
height: 100%;
98+
width: 100%;
99+
}
100+
101+
102+
.card .img {
103+
width: 370px;
104+
height: 180px;
105+
}
106+
107+
.card .img img {
108+
height: 100%;
109+
width: 100%;
110+
}
111+
112+
.text {
113+
padding: 13px 9px;
114+
}
115+
116+
.text h3 {
117+
font-weight: 300;
118+
color: black;
119+
font-size: 22px;
120+
}
121+
122+
.text p {
123+
color: rgb(138, 138, 138);
124+
font-size: 13px;
125+
line-height: 1.5;
126+
padding: 10px 9px;
127+
}
128+
129+
@media (max-width: 1290px) {
130+
.main,
131+
.tesla-main {
132+
padding: 0 40px;
133+
}
134+
}
135+
136+
@media (max-width: 830px) {
137+
.card-container {
138+
justify-content: space-around;
139+
}
140+
}
141+
142+
@media (max-width: 410px) {
143+
.tesla-main {
144+
padding: 0 10px;
145+
}
146+
}

news-app/src/Components/Main.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React, { useState, useEffect } from "react";
2+
import "./Main.css";
3+
4+
const Main = () => {
5+
const [news, setNews] = useState([]);
6+
const [tnews, setTNews] = useState([]);
7+
8+
const loadNews = async () => {
9+
const response = await fetch(
10+
"https://newsapi.org/v2/everything?q=Apple&from=2021-07-19&sortBy=popularity&apiKey=4fc8ad23db54411c8dce19801bccff07"
11+
);
12+
const data = await response.json();
13+
setNews(data.articles);
14+
};
15+
16+
const loadTesla = async () => {
17+
const response = await fetch("https://newsapi.org/v2/everything?q=tesla&from=2021-06-19&sortBy=publishedAt&apiKey=4fc8ad23db54411c8dce19801bccff07");
18+
const data = await response.json();
19+
console.log(data.articles);
20+
setTNews(data.articles);
21+
console.log(tnews)
22+
}
23+
24+
useEffect(() => {
25+
loadNews();
26+
loadTesla();
27+
}, []);
28+
29+
30+
return (
31+
<div className="main">
32+
<h2 className="main-heading">Latest News</h2>
33+
34+
<div className="card-container">
35+
{news.map((data) => {
36+
return (
37+
<div className="card">
38+
<div className="img">
39+
<img src={data.urlToImage} alt="" />
40+
</div>
41+
<div className="text">
42+
<h3>{data.title}</h3>
43+
<p>{data.description}</p>
44+
</div>
45+
</div>
46+
);
47+
})}
48+
</div>
49+
<div className="tesla-main">
50+
<h2 className="tesla-heading">Tesla News</h2>
51+
52+
<div className="tesla-container">
53+
{tnews.map(data => {
54+
return(
55+
<div className="card1">
56+
<div className="image">
57+
<img src={data.urlToImage} alt="" />
58+
</div>
59+
<div className="info">
60+
<h3>{data.title}</h3>
61+
62+
<p>{data.description}</p>
63+
</div>
64+
</div>
65+
);
66+
})}
67+
</div>
68+
</div>
69+
</div>
70+
71+
);
72+
};
73+
74+
export default Main;

0 commit comments

Comments
 (0)