-
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.
Merge pull request #482 from bounswe/feature/FE-comments-likes
Add comments, likes. Fix tags
- Loading branch information
Showing
6 changed files
with
223 additions
and
149 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
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 |
---|---|---|
@@ -1,62 +1,62 @@ | ||
import React from 'react'; | ||
import { FaHeart, FaComment } from 'react-icons/fa'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import '../../styles/community/PostCard.css'; | ||
import React from "react"; | ||
import { FaHeart, FaComment } from "react-icons/fa"; | ||
import { useNavigate } from "react-router-dom"; | ||
import "../../styles/community/PostCard.css"; | ||
|
||
const getColorForTag = (tag) => { | ||
const asciiValue = tag.charCodeAt(0); | ||
const colors = [ | ||
'#3498db', | ||
'#e74c3c', | ||
'#2ecc71', | ||
'#f1c40f', | ||
'#9b59b6' | ||
]; | ||
return colors[asciiValue % 5]; | ||
const tagName = typeof tag === "string" ? tag : tag.name; | ||
const asciiValue = tagName.charCodeAt(0); | ||
const colors = ["#3498db", "#e74c3c", "#2ecc71", "#f1c40f", "#9b59b6"]; | ||
return colors[asciiValue % 5]; | ||
}; | ||
|
||
const PostCard = ({ post }) => { | ||
const navigate = useNavigate(); | ||
const navigate = useNavigate(); | ||
|
||
const navigateToPost = (postId) => { | ||
navigate(`/post/${postId}`); | ||
}; | ||
const navigateToPost = (postId) => { | ||
navigate(`/post/${postId}`); | ||
}; | ||
|
||
return ( | ||
<div className="post-card"> | ||
<div className="post-header"> | ||
<h2>{post.title}</h2> | ||
<p className="post-meta"> | ||
Published on: <span>{new Date(post['publication-date']).toLocaleDateString()}</span> by <span>{post['user']}</span> | ||
</p> | ||
</div> | ||
<p>{post.content[0]["plain-text"]}</p> | ||
<div className="post-info"> | ||
<div className="post-stats"> | ||
<span className="likes"> | ||
<FaHeart className="icon like-icon" /> {post.likes} | ||
</span> | ||
<span className="comments-box"> | ||
<FaComment className="icon comment-icon" /> { post.comments.length } | ||
</span> | ||
</div> | ||
<button className="view-button" onClick={() => navigateToPost(post["post-id"])}> | ||
View Post | ||
</button> | ||
</div> | ||
<div className="post-tags"> | ||
{post.tags.map((tag, index) => ( | ||
<span | ||
key={index} | ||
className="post-tag" | ||
style={{ backgroundColor: getColorForTag(tag) }} | ||
> | ||
{tag} | ||
</span> | ||
))} | ||
</div> | ||
return ( | ||
<div className="post-card"> | ||
<div className="post-header"> | ||
<h2>{post.title}</h2> | ||
<p className="post-meta"> | ||
Published on:{" "} | ||
<span>{new Date(post["publication-date"]).toLocaleDateString()}</span>{" "} | ||
by <span>{post["user"]}</span> | ||
</p> | ||
</div> | ||
<p>{post.content[0]["plain-text"]}</p> | ||
<div className="post-info"> | ||
<div className="post-stats"> | ||
<span className="likes"> | ||
<FaHeart className="icon like-icon" /> {post.likes} | ||
</span> | ||
<span className="comments-box"> | ||
<FaComment className="icon comment-icon" /> {post.comments.length} | ||
</span> | ||
</div> | ||
); | ||
<button | ||
className="view-button" | ||
onClick={() => navigateToPost(post["post-id"])} | ||
> | ||
View Post | ||
</button> | ||
</div> | ||
<div className="post-tags"> | ||
{post.tags.map((tag, index) => ( | ||
<span | ||
key={index} | ||
className="post-tag" | ||
style={{ backgroundColor: getColorForTag(tag) }} | ||
> | ||
{tag} | ||
</span> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PostCard; |
Oops, something went wrong.