Skip to content

Commit a32c5ec

Browse files
committed
only creator can delete or edit
1 parent 95c25ed commit a32c5ec

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

blog-frontend/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const App : React.FC = () => {
6262
published={post.published}
6363
category={post.category}
6464
deletePost={deletePost}
65+
user={user}
6566
/>
6667
))
6768
}

blog-frontend/src/components/PostCard.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import moment from 'moment'
22
import React from 'react'
33
import { Link } from 'react-router-dom'
44

5-
interface Snippet {
5+
interface PostCardProps {
66
title: string;
77
author: string;
88
excerpt: string;
99
status:string;
1010
published: string;
1111
category?: string[];
1212
deletePost: (title:string)=>void
13+
user: string
1314
}
1415

15-
const PostCard : React.FC <Snippet> = ({title,author,excerpt,status,published,category, deletePost}) => {
16+
const PostCard : React.FC <PostCardProps> = ({title,author,excerpt,status,published,category, deletePost, user}) => {
1617

1718
return (
1819
<div
@@ -31,6 +32,8 @@ const PostCard : React.FC <Snippet> = ({title,author,excerpt,status,published,ca
3132
<small>Categories: {category}</small>
3233
</Link>
3334
<br/>
35+
{author===user&&(
36+
<>
3437
<Link
3538
to={{
3639
pathname: `posts/:title/edit`
@@ -39,6 +42,8 @@ const PostCard : React.FC <Snippet> = ({title,author,excerpt,status,published,ca
3942
Edit
4043
</Link>
4144
<button onClick={()=>deletePost(title)}>Delete</button>
45+
</>)
46+
}
4247
</div>
4348
)
4449
}

0 commit comments

Comments
 (0)