Skip to content

Commit

Permalink
fix: 속성으로 처리하여 로그아웃 후에도 좋아요의 색상이 여전히 파란색인 이슈 username 포함 여부 확인 로직으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
junman95 committed Dec 27, 2024
1 parent 3db4eae commit 70f9469
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 3 additions & 9 deletions src/components/posts/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import { addEvent, createVNode } from "../../lib";
import { globalStore } from "../../stores/globalStore.js";
import { toTimeFormat } from "../../utils/index.js";

export const Post = ({
id,
author,
time,
content,
likeUsers,
activationLike = false,
}) => {
export const Post = ({ id, author, time, content, likeUsers }) => {
const { currentUser } = globalStore.getState();
const { like } = globalStore.actions;

const onClickLike = () => {
Expand All @@ -28,7 +22,7 @@ export const Post = ({
<p>{content}</p>
<div className="mt-2 flex justify-between text-gray-500">
<span
className={`like-button cursor-pointer${activationLike ? " text-blue-500" : ""}`}
className={`like-button cursor-pointer${likeUsers.includes(currentUser?.username) ? " text-blue-500" : ""}`}
onClick={onClickLike}
>
좋아요 {likeUsers.length}
Expand Down
2 changes: 0 additions & 2 deletions src/stores/globalStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ export const globalStore = createStore(
post.likeUsers = post.likeUsers.filter(
(username) => username !== state.currentUser.username,
);
post.activationLike = false;
} else {
post.likeUsers.push(state.currentUser.username);
post.activationLike = true;
}
},
},
Expand Down

0 comments on commit 70f9469

Please sign in to comment.