File tree 5 files changed +107
-1
lines changed
5 files changed +107
-1
lines changed Original file line number Diff line number Diff line change
1
+ .container {
2
+ display : flex;
3
+ flex-direction : row;
4
+ flex-wrap : wrap;
5
+ max-width : 900px ;
6
+ margin : auto;
7
+ }
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import './App.css' ;
3
+ import BlogPosts from './BlogPosts'
3
4
4
5
function App ( ) {
5
6
return (
6
7
< div >
7
- hi
8
+ < BlogPosts />
8
9
</ div >
9
10
) ;
10
11
}
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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 ;}
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments