File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,8 @@ const PostForm =()=>{
69
69
title :dataInputs . title ,
70
70
country :dataInputs . country ,
71
71
state :dataInputs . state ,
72
- days :dataInputs . day
72
+ days :dataInputs . day ,
73
+ likes :0
73
74
} )
74
75
. then ( ( res ) => {
75
76
console . log ( "data received" )
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
+ import axios from 'axios' ;
2
3
3
4
import history from './../history' ;
4
5
const PostList = ( { posts} ) => {
5
-
6
+ const like_post = ( e , post_id ) => {
7
+ e . preventDefault ( ) ;
8
+
9
+ console . log ( "new" , posts [ 0 ] . id , post_id )
10
+ for ( let i = 0 ; i < posts . length ; i ++ ) {
11
+ if ( post_id == posts [ i ] . id ) {
12
+ console . log ( "yes" )
13
+ posts [ i ] . likes += 1
14
+ axios . patch ( `http://localhost:5000/travelposts/${ post_id } ` , {
15
+ likes_count :posts [ i ] . likes
16
+ } )
17
+ }
18
+ }
19
+
20
+ }
21
+
6
22
return (
7
23
< div >
8
24
< h1 > post</ h1 >
@@ -15,8 +31,12 @@ const PostList = ({posts})=>{
15
31
{ post . days . map ( ( days , i ) => {
16
32
17
33
if ( i === 0 ) {
18
- return ( < img onClick = { ( ) => history . push ( `/postCard/${ post . id } ` ) } height = "200" width = "300" src = { days . photosList [ 0 ] . photo } alt = "post cover picture" /> )
34
+ return (
35
+ < div >
36
+ < img onClick = { ( ) => history . push ( `/postCard/${ post . id } ` ) } height = "200" width = "300" src = { days . photosList [ 0 ] . photo } alt = "post cover picture" />
37
+ </ div > )
19
38
} } ) }
39
+ < p onClick = { ( e ) => like_post ( e , post . id ) } > 💗{ post . likes } </ p >
20
40
< p onClick = { ( ) => history . push ( `/postCard/${ post . id } ` ) } > { post . title } </ p >
21
41
{ post . state } -{ post . country }
22
42
</ div >
You can’t perform that action at this time.
0 commit comments