diff --git a/src/App.jsx b/src/App.jsx index eae2495..419597b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,54 +1,21 @@ -import React, { useState, useEffect } from "react"; +import React from "react"; import Post from "./components/Post"; -import ActionButtons from "./components/ActionButtons"; -import CommentForm from "./components/CommentForm"; -import CommentsModal from "./components/CommentsModal"; const App = () => { - // State declarations - const [likes, setLikes] = useState(0); - const [comments, setComments] = useState([]); - const [newComment, setNewComment] = useState(""); - const [showComments, setShowComments] = useState(false); - - // Persist likes and comments in localStorage - useEffect(() => { - localStorage.setItem("likes", likes); - }, [likes]); - - useEffect(() => { - localStorage.setItem("comments", JSON.stringify(comments)); - }, [comments]); - - // Handlers - const handleLike = () => setLikes((prev) => prev + 1); - - const handleSubmit = (e) => { - e.preventDefault(); - if (newComment.trim()) { - setComments((prev) => [...prev, { text: newComment }]); - setNewComment(""); + const posts = [ + { + id: 1, + user: "John Doe", + time: "2 hours ago", + content: "This is a sample post content. Implementing concepts of Likes and Comments.", + image: "/images/Blog.webp", } - }; - + ]; return (
- -
- {likes} likes - {comments.length} comments -
- - - + {posts.map((post) => ( + + ))}
); }; diff --git a/src/components/Post.jsx b/src/components/Post.jsx index 04820b0..3a00eff 100644 --- a/src/components/Post.jsx +++ b/src/components/Post.jsx @@ -1,25 +1,54 @@ -import React from "react"; +import React, { useState } from "react"; +import ActionButtons from "./ActionButtons"; +import CommentForm from "./CommentForm"; +import CommentsModal from "./CommentsModal"; -const Post = () => ( -
-
-
- User Avatar +const Post = ({ user, time, content, image }) => { + const [likes, setLikes] = useState(0); + const [comments, setComments] = useState([]); + const [newComment, setNewComment] = useState(""); + const [showComments, setShowComments] = useState(false); + + const handleLike = () => setLikes((prev) => prev + 1); + + const handleSubmit = (e) => { + e.preventDefault(); + if (newComment.trim()) { + setComments((prev) => [...prev, { text: newComment }]); + setNewComment(""); + } + }; + + return ( +
+
+
+ {`${user}'s +
+
+

{user}

+

{time}

+
-
-

John Doe

-

2 hours ago

+

{content}

+ {image && Post content} +
+ {likes} likes + {comments.length} comments
+ + +
-

- This is a sample post content. Implementing concepts of Likes and Comments. -

- Post content -
-); + ); +}; export default Post;