Skip to content

Commit

Permalink
feat : e2e 테스트 통과되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hanghaehyunjin committed Dec 26, 2024
1 parent baf8b81 commit 744a7cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions src/components/posts/Post.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @jsx createVNode */
import { createVNode } from "../../lib";
import { userStorage } from "../../storages/userStorage.js";
import { globalStore } from "../../stores/globalStore.js";
import { toTimeFormat } from "../../utils/index.js";

Expand All @@ -13,27 +12,29 @@ export const Post = ({
activationLike = false,
}) => {
const addLike = () => {
const { posts } = globalStore.getState();
const username = userStorage.get("user")?.username;
const { posts, loggedIn, currentUser } = globalStore.getState();

if (!username) return;
if (!loggedIn) {
alert("로그인 후 이용해주세요");
return;
}

globalStore.setState({
posts: posts.map((post) => {
if (post.id !== id) return post;

if (post.likeUsers.includes(username)) {
if (post.likeUsers.includes(currentUser.username)) {
return {
...post,
likeUsers: post.likeUsers.filter(
(likeUser) => likeUser !== username,
(likeUser) => likeUser !== currentUser.username,
),
};
}

return {
...post,
likeUsers: [username, ...post.likeUsers],
likeUsers: [currentUser.username, ...post.likeUsers],
};
}),
});
Expand All @@ -51,13 +52,7 @@ export const Post = ({
<div className="mt-2 flex justify-between text-gray-500">
<span
className={`like-button cursor-pointer${activationLike ? " text-blue-500" : ""}`}
onClick={() => {
if (!userStorage.get("user")) {
alert("로그인 후 이용해주세요");
} else {
addLike();
}
}}
onClick={addLike}
>
좋아요 {likeUsers.length}
</span>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { userStorage } from "../storages";
* - 로그인하지 않은 사용자가 게시물에 좋아요를 누를 경우, "로그인 후 이용해주세요"를 alert로 띄운다.
*/
export const HomePage = () => {
const { posts } = globalStore.getState();
const { posts, loggedIn } = globalStore.getState();

const isChecked = (likeUsers) => {
return likeUsers.find((postLike) =>
Expand All @@ -27,7 +27,7 @@ export const HomePage = () => {
<Navigation />

<main className="p-4">
{!!userStorage.get("user") && <PostForm />}
{loggedIn && <PostForm />}
<div id="posts-container" className="space-y-4">
{[...posts]
.sort((a, b) => b.time - a.time)
Expand Down

0 comments on commit 744a7cc

Please sign in to comment.