PostCard.js
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { useContext } from "react";
import { Card, Image, Button, Label, Icon } from "semantic-ui-react";
import moment from "moment";
import { Link } from "react-router-dom";
import { AuthContext } from "../context/auth";
import LikeButton from "./LikeButton";
const PostCard = ({
post: { username, body, id, createdAt, likeCount, commentCount, likes }
}) => {
const { user } = useContext(AuthContext);
return (
<Card fluid>
<Card.Content>
<Image
floated="right"
size="mini"
src="https://react.semantic-ui.com/images/avatar/large/steve.jpg"
/>
<Card.Header>{username} </Card.Header>
<Card.Meta as={Link} to={`/posts/${id}`}>
{moment(createdAt).fromNow(true)}
</Card.Meta>
<Card.Description>{body}</Card.Description>
</Card.Content>
<Card.Content extra>
<LikeButton user={user} post={{ id, likes, likeCount }} />
<Button labelPosition="right" as={Link} to={`/posts/${id}`}>
<Button color="blue" basic>
<Icon name="comment" />
</Button>
<Label basic color="blue" pointing="left">
{commentCount}
</Label>
</Button>
{user && user.username === username && (
<Button
onClick={() => console.log("deleted")}
as="div"
color="red"
floated="right"
>
<Icon name="trash" style={{ margin: 0 }} />
</Button>
)}
</Card.Content>
</Card>
);
};
export default PostCard;