forked from KevinEboda/acebook-krypton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created individual post and comment components
- Loading branch information
1 parent
6d063e8
commit 1074c8b
Showing
9 changed files
with
187 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from "react"; | ||
import { LikeCommentButton } from "../Like/Like"; | ||
import "./Comment.css"; | ||
|
||
const Comment = ({ comments, loggedInUser, fetchComments }) => { | ||
const addOrdinalSuffix = (day) => { | ||
if (day === 1 || day === 21 || day === 31) return day + "st"; | ||
if (day === 2 || day === 22) return day + "nd"; | ||
if (day === 3 || day === 23) return day + "rd"; | ||
return day + "th"; | ||
}; | ||
|
||
const formatDate = (createdAt) => { | ||
const date = new Date(createdAt); | ||
const day = addOrdinalSuffix(date.getDate()); | ||
const month = date.toLocaleString("en-GB", { month: "short" }); | ||
const time = date.toLocaleString("en-GB", { | ||
hour: "numeric", | ||
minute: "numeric", | ||
}); | ||
|
||
return `${day} ${month} ${date.getFullYear()} at ${time}`; | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div> | ||
{comments.map((comment) => ( | ||
<div className="comment-container" key={comment._id}> | ||
<div className="comment-content"> | ||
<div className="comment-user"> | ||
<img | ||
className="comment-profilePicture" | ||
src={comment.user.profilePicture} | ||
alt={comment.user.fullName} | ||
/> | ||
<div className="comment-date-and-name"> | ||
<div className="comment-fullName"> | ||
{comment.user.fullName} | ||
</div> | ||
<div className="comment-date"> | ||
{formatDate(comment.createdAt)} | ||
</div> | ||
</div> | ||
</div> | ||
<div className="comment-text">{comment.comment_text}</div> | ||
<div className="comment-like-button"> | ||
<LikeCommentButton | ||
commentId={comment._id} | ||
isLiked={comment.likedBy.includes(loggedInUser)} | ||
updateCommentLikeFeed={fetchComments} | ||
/> | ||
</div> | ||
<div className="comment-like-count">{comment.likedBy.length}</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Comment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useEffect } from "react"; | ||
import { LikePostButton } from "../Like/Like"; | ||
import Comments from "../Comment/Comments"; | ||
import "./Post.css"; | ||
|
||
const Post = ({ posts, loggedInUser, fetchPosts }) => { | ||
const addOrdinalSuffix = (day) => { | ||
if (day === 1 || day === 21 || day === 31) return day + "st"; | ||
if (day === 2 || day === 22) return day + "nd"; | ||
if (day === 3 || day === 23) return day + "rd"; | ||
return day + "th"; | ||
}; | ||
|
||
const formatDate = (createdAt) => { | ||
const date = new Date(createdAt); | ||
const day = addOrdinalSuffix(date.getDate()); | ||
const month = date.toLocaleString("en-GB", { month: "short" }); | ||
const time = date.toLocaleString("en-GB", { | ||
hour: "numeric", | ||
minute: "numeric", | ||
}); | ||
|
||
return `${day} ${month} ${date.getFullYear()} at ${time}`; | ||
}; | ||
|
||
return ( | ||
<> | ||
<div> | ||
{posts.map((post) => ( | ||
<div className="post" key={post._id}> | ||
<div className="post-border"> | ||
<div className="post-header-container"> | ||
<img | ||
className="post-profile_picture" | ||
src={post.user.profilePicture} | ||
alt="Profile" | ||
/> | ||
<div> | ||
<div className="post-user-fullName">{post.user.fullName}</div> | ||
<div className="post-date">{formatDate(post.createdAt)}</div> | ||
</div> | ||
</div> | ||
{post.image && ( | ||
<img className="post_image" src={post.image} alt="Post" /> | ||
)} | ||
<div className="post-message">{post.message}</div> | ||
<div className="post-like-button"> | ||
<LikePostButton | ||
postId={post._id} | ||
isLiked={post.likedBy.includes(loggedInUser)} | ||
updatePostLikeFeed={fetchPosts} | ||
/> | ||
</div> | ||
<div className="post-like-counter">{post.likedBy.length}</div> | ||
</div> | ||
<div> | ||
<Comments postId={post._id} /> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Post; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.