diff --git a/src/components/PostsCard.jsx b/src/components/PostsCard.jsx index 60a66041..9fc3abdb 100644 --- a/src/components/PostsCard.jsx +++ b/src/components/PostsCard.jsx @@ -1,33 +1,90 @@ +import { useState } from "react"; +import PropTypes from "prop-types"; + const PostCard = ({ post }) => { - return ( -
- {/* Optional Post Image */} - {post.image_url ? ( - {post.title} - ) : ( -
- No Image -
- )} + const [liked, setLiked] = useState(false); + const [likeCount, setLikeCount] = useState(post.likes || 0); + + const handleLike = () => { + setLiked(!liked); + setLikeCount(prev => liked ? prev - 1 : prev + 1); + // Optional: Send API request to backend here + }; + + const handleShare = (e) => { + e.stopPropagation(); + const shareData = { + title: post.title, + text: post.content, + url: window.location.origin + `/post/${post.id}`, + }; - {/* Post Content */} -
-

{post.title}

-

{post.content}

+ if (navigator.share) { + navigator + .share(shareData) + .then(() => console.log("Post shared successfully")) + .catch((error) => console.error("Sharing failed:", error)); + } else { + // Fallback for unsupported browsers + navigator.clipboard.writeText(shareData.url); + alert("Share not supported on this browser. Link copied to clipboard!"); + } + }; + + return ( +
+ {post.image_url ? ( + {post.title} + ) : ( +
+ No Image
- - {/* Optional Post Location */} - {post.location && ( -
- 📍 {post.location} -
- )} + )} + +
+

{post.title}

+

{post.content}

- ); - }; - - export default PostCard; \ No newline at end of file + + {post.location && ( +
+ 📍 {post.location} +
+ )} + +
+ + +
+
+ ); +}; + +PostCard.propTypes = { + post: PropTypes.shape({ + id: PropTypes.string.isRequired, + title: PropTypes.string.isRequired, + content: PropTypes.string.isRequired, + image_url: PropTypes.string, + location: PropTypes.string, + likes: PropTypes.number, + }).isRequired, +}; + +export default PostCard; \ No newline at end of file diff --git a/src/components/PostsFeed.jsx b/src/components/PostsFeed.jsx index 1b134165..23dbc607 100644 --- a/src/components/PostsFeed.jsx +++ b/src/components/PostsFeed.jsx @@ -1,11 +1,10 @@ -import React from "react"; -import { Link } from "react-router-dom"; import PostCard from "./PostsCard"; // ✅ Correct import +import PropTypes from "prop-types"; -const PostsFeed = ({ type = "friends" }) => { - console.log("Rendering PostsFeed with type:", type); // ✅ Debugging - // Example post data +const PostsFeed = ({ type = "friends" }) => { + console.log("Rendering PostsFeed with type:", type); + const allPosts = [ { id: 1, @@ -41,17 +40,19 @@ const PostsFeed = ({ type = "friends" }) => { }, ]; - const posts = type === "friends" ? allPosts.slice(0, 2) : allPosts; // ✅ Show all for "all" type + const posts = type === "friends" ? allPosts.slice(0, 2) : allPosts; return (
{posts.map((post) => ( - - - + ))}
); }; +PostsFeed.propTypes = { + type: PropTypes.string +}; + export default PostsFeed; \ No newline at end of file