diff --git a/src/components/posts/Post.jsx b/src/components/posts/Post.jsx index 67af756..d3d5e38 100644 --- a/src/components/posts/Post.jsx +++ b/src/components/posts/Post.jsx @@ -1,14 +1,31 @@ /** @jsx createVNode */ import { createVNode } from "../../lib"; import { toTimeFormat } from "../../utils/index.js"; +import { globalStore } from "../../stores/index.js"; + +export const Post = ({ author, time, content, likeUsers }) => { + const { loggedIn, currentUser, posts } = globalStore.getState(); + const activationLike = likeUsers.includes(currentUser?.username); + const handleLike = () => { + if (!currentUser) { + alert("로그인 후 이용해주세요"); + return; + } + + const newPosts = posts.map((post) => { + if (post.author === author && post.time === time) { + return { + ...post, + likeUsers: activationLike + ? post.likeUsers.filter((user) => user !== currentUser.username) + : [...post.likeUsers, currentUser?.username], + }; + } + return post; + }); + globalStore.setState({ posts: newPosts }); + }; -export const Post = ({ - author, - time, - content, - likeUsers, - activationLike = false, -}) => { return (
{content}