Skip to content

Commit c0ecfa2

Browse files
committed
added blog previews
1 parent d812a72 commit c0ecfa2

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed

src/components/App.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.container{
2+
display:flex;
3+
flex-direction:row;
4+
flex-wrap:wrap;
5+
max-width:900px;
6+
margin:auto;
7+
}

src/components/App.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import './App.css';
3+
import BlogPosts from './BlogPosts'
34

45
function App() {
56
return (
67
<div>
7-
hi
8+
<BlogPosts/>
89
</div>
910
);
1011
}

src/components/BlogPosts.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import Post from './Post';
3+
import './App.css';
4+
5+
const query = `
6+
{
7+
user(username: "rutikwankhade") {
8+
publication {
9+
posts{
10+
slug
11+
title
12+
brief
13+
coverImage
14+
}
15+
}
16+
}
17+
}
18+
`;
19+
20+
class Blogposts extends React.Component {
21+
state = {
22+
posts: []
23+
};
24+
25+
componentDidMount() {
26+
this.fetchPosts();
27+
}
28+
29+
fetchPosts = async () => {
30+
const response = await fetch('https://api.hashnode.com', {
31+
method: 'POST',
32+
headers: {
33+
'Content-type': 'application/json',
34+
},
35+
body: JSON.stringify({ query }),
36+
})
37+
const ApiResponse = await response.json();
38+
39+
console.log(ApiResponse.data.user.publication.posts);
40+
this.setState({ posts: ApiResponse.data.user.publication.posts});
41+
42+
43+
};
44+
45+
render() {
46+
return (
47+
<div class="container">
48+
{this.state.posts.map((post, index) => (
49+
<a key={index} href={`https://blog.rutikwankhade.dev/${post.slug}`} >
50+
<Post post={post}/>
51+
</a>
52+
))}
53+
</div>
54+
);
55+
}
56+
}
57+
58+
59+
export default Blogposts;

src/components/Post.css

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.card{
2+
height:auto;
3+
width:350px;
4+
padding:20px;
5+
font-family:segoe ui;
6+
border:solid 2px #f2f2f2;
7+
text-align: inherit;
8+
margin:20px;
9+
background-color: #ffffff;
10+
box-shadow:2px 2px 4px #f2f2f2;
11+
border-radius:8px;
12+
}
13+
p{color:#333333;}
14+
15+
h2{
16+
font-weight:600;
17+
}
18+
img{
19+
20+
width:inherit;
21+
height:inherit;
22+
border-radius:5px;
23+
}
24+
25+
a{text-decoration: none;
26+
color:#1d1d1d;}

src/components/Post.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import './Post.css'
3+
const Post = ({ post }) => {
4+
return (
5+
<div className="card">
6+
<img src={post.coverImage} alt={post.title}/>
7+
<h2>{post.title}</h2>
8+
<p>{post.brief}</p>
9+
</div>
10+
)
11+
}
12+
13+
export default Post;

0 commit comments

Comments
 (0)