Skip to content

Commit dce4025

Browse files
committed
made changes
2 parents b324053 + 1cce389 commit dce4025

File tree

9 files changed

+676
-522
lines changed

9 files changed

+676
-522
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "bootstrap/dist/css/bootstrap.min.css";
66
import Registration from "./components/registration";
77
import Login from "./components/login";
88
import Facebook from "./components/facebook";
9-
import User from "./components/user";
9+
import User from "./components/user/index";
1010
import CreateArticle from "./components/create-article";
1111
import ArticleView from "./components/article/article-view";
1212
import PrivateRoute from "./components/privateRoutes";

src/components/article/Bookmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Bookmark = () => {
1010
(state) => state.userReducer.bookmarks,
1111
shallowEqual
1212
);
13-
const { _id } = useSelector(
13+
const { _id, user } = useSelector(
1414
(state) => state.articlesReducer.article,
1515
shallowEqual
1616
);

src/components/article/article-view.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ class ArticleView extends Component {
274274
this.props.dispatch(deleteArticle(this.props.match.params.id));
275275
window.location = "/";
276276
};
277+
showBookmark = () => {
278+
if (
279+
this.props.loggedIn &&
280+
this.props.user.id !== this.state.articleDetails.user_id
281+
) {
282+
return <Bookmark />;
283+
}
284+
};
277285

278286
render() {
279287
return (
@@ -289,8 +297,7 @@ class ArticleView extends Component {
289297
</h6>
290298

291299
<Like />
292-
{this.props.loggedIn ? <Bookmark /> : ""}
293-
300+
{this.showBookmark()}
294301
{this.editAndDeleArticle()}
295302

296303
<hr />

src/components/article/article.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from "react";
22
import { Link } from "react-router-dom";
3+
import { formatDistanceToNow } from "date-fns";
4+
35
const Article = (props) => {
6+
var date = new Date(props.article.createdAt);
7+
48
return (
59
<div className="card">
610
<div className="card-body">
@@ -16,7 +20,7 @@ const Article = (props) => {
1620
{props.article.user.name}
1721
</Link>
1822
<br />
19-
<b>Created at - </b> {props.article.createdAt.substring(0, 10)}
23+
<b>{formatDistanceToNow(date)} ago</b>
2024
<br />
2125
</div>
2226
</div>

0 commit comments

Comments
 (0)