Skip to content

Commit

Permalink
Fix delete button not rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
markohanesian committed Jul 11, 2024
1 parent bf6b2a7 commit 4173363
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/components/CreatePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function CreatePost() {
imagePreview.src = selectedImageSrc;
imagePreview.style.display = "block";
}

};

const handleUpload = () => {
Expand Down Expand Up @@ -61,15 +62,17 @@ export default function CreatePost() {
uploadURL: imageUrl,
username: user.email.replace("@gmail.com", ""),
avatar: user.photoURL,
// Ensure ownerEmail is set to user's email
ownerEmail: user.email,
});

setCaption("");
setProgress(0);
setImage(null);
document.getElementById("image-preview").style.display = "none";
setLoading(false);

});

}
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Feed = () => {
const postsData = querySnapshot.docs.map((doc) => ({
id: doc.id,
post: doc.data(),
ownerId: doc.data().ownerEmail // Adjust according to your data structure
ownerEmail: doc.data().ownerEmail, // Ensure ownerEmail is included
}));

setPosts(postsData);
Expand Down Expand Up @@ -55,7 +55,7 @@ const Feed = () => {
return (
<div style={FeedStyle}>
<CreatePost />
{posts.map(({ id, post, ownerId }) => (
{posts.map(({ id, post, ownerEmail }) => (
<Post
key={id}
id={id}
Expand All @@ -65,7 +65,7 @@ const Feed = () => {
caption={post.caption}
comments={post.comments}
onDelete={handleDeletePost}
ownerId={ownerId} // Pass ownerId to Post component
ownerEmail={ownerEmail} // Pass ownerEmail to Post component
/>
))}
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/components/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export default function Post({
ownerEmail,
}) {
const { user } = useContext(UserContext); // Destructure user from context
const userEmail = user && user.length > 0 ? user[0].email : null;

// console.log("Owner Email:", ownerEmail); // Log ownerEmail to verify in the browser console
console.log("User email:", userEmail); // Log user to verify in the browser console

const handleDelete = async () => {
try {
Expand All @@ -75,7 +79,7 @@ export default function Post({
}
};

const isPostOwner = user && user.email === ownerEmail;
const isPostOwner = user && userEmail === ownerEmail;

return (
<div style={PostStyle}>
Expand Down

0 comments on commit 4173363

Please sign in to comment.