File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed
Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -132,12 +132,51 @@ const Home = () => {
132132 } ) ;
133133 } ;
134134
135+ const deletePost = ( postId ) => {
136+ fetch ( `/posts/comment/${ postId } ` , {
137+ method : "DELETE" ,
138+ headers : {
139+ Authorization : `Bearer ${ localStorage . getItem ( "authorization" ) } ` ,
140+ "IMS-Request-Id" : getUUIDV4 ( ) . toString ( ) ,
141+ "IMS-Request-Date" : new Date ( ) . toISOString ( ) ,
142+ } ,
143+ } )
144+ . then ( ( res ) => {
145+ return res . json ( ) ;
146+ } )
147+ . then ( ( result ) => {
148+ console . log ( "DELETE POST RESULT:" , result ) ;
149+ const newData = data . filter ( ( item ) => {
150+ console . log ( "item._id:" , item . _id ) ;
151+ console . log ( "result.post._id:" , result . post . _id ) ;
152+ return item . _id !== result . post . _id ;
153+ } ) ;
154+ return setData ( newData ) ;
155+ } )
156+ . catch ( ( err ) => {
157+ console . log ( "ERROR CATCH DELETE POST:" , err ) ;
158+ } ) ;
159+ } ;
160+
135161 return (
136162 < div className = "home" >
137163 { data . map ( ( item ) => {
138164 return (
139165 < div key = { item . _id } className = "card home-card" >
140- < h5 > @{ newState . username } </ h5 >
166+ < h5 >
167+ @{ newState . username }
168+ { item . postedBy . _id === newState . _id && (
169+ < i
170+ className = "material-icons"
171+ onClick = { ( ) => {
172+ deletePost ( item . _id ) ;
173+ } }
174+ style = { { float : "right" } }
175+ >
176+ delete
177+ </ i >
178+ ) }
179+ </ h5 >
141180 < div className = "card-image" >
142181 < img src = { item . photo } alt = "card-pic" />
143182 </ div >
You can’t perform that action at this time.
0 commit comments