Skip to content

Commit

Permalink
Refactor : isFollowedByMe 추가에 따른 버튼 분기
Browse files Browse the repository at this point in the history
  • Loading branch information
jobkaeHenry committed Dec 15, 2023
1 parent df6222d commit bb113ad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
27 changes: 20 additions & 7 deletions client/src/components/user/followList/FollowUserCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import UserAvatar from "@/components/user/info/UserAvatar";
import { useRouter } from "next/navigation";
import { USER_PAGE } from "@/const/clientPath";
import useUnFollowMutation from "@/queries/user/useUnFollowMutation";
import useFollowMutation from "@/queries/user/useFollowMutation";

type Props = {
imageUrl?: string;
nickName: string;
userId: string;
content: string;
userPk: number;
isFollowedByMe?: boolean;
};

const FollowUserCard = ({
Expand All @@ -19,10 +21,11 @@ const FollowUserCard = ({
nickName,
userId,
content,
isFollowedByMe,
}: Props) => {
const router = useRouter();
const { mutate: unfollowHandler } = useUnFollowMutation();

const { mutate: followHandler } = useFollowMutation();
return (
<Stack direction="row" gap={1} py={1}>
<UserAvatar
Expand All @@ -45,12 +48,22 @@ const FollowUserCard = ({
@{userId}
</Typography>
</Stack>
<Button
variant="outlined"
onClick={() => unfollowHandler(String(userPk))}
>
언팔로우
</Button>

{isFollowedByMe ? (
<Button
variant="outlined"
onClick={() => unfollowHandler(String(userPk))}
>
언팔로우
</Button>
) : (
<Button
variant="contained"
onClick={() => followHandler(String(userPk))}
>
팔로우
</Button>
)}
</Stack>
<Typography>{content}</Typography>
</Stack>
Expand Down
21 changes: 12 additions & 9 deletions client/src/components/user/followList/FollowerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ const FollowerList = () => {
return (
<>
{data.pages.map((page) =>
page.content.map(({ nickname, id, introduction, userNo }) => (
<FollowUserCard
key={id}
nickName={nickname}
userId={id}
userPk={userNo}
content={introduction}
/>
))
page.content.map(
({ nickname, id, introduction, userNo, isFollowedByMe }) => (
<FollowUserCard
key={id}
nickName={nickname}
userId={id}
userPk={userNo}
isFollowedByMe={isFollowedByMe}
content={introduction}
/>
)
)
)}
{isFetchingNextPage ? (
<ComponentRepeater count={5}>
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/user/followList/FollowingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const FollowingList = () => {
return (
<>
{data.pages.map((page) =>
page.content.map(({ nickname, id, introduction, profileImgUrls, userNo }) => (
page.content.map(({ nickname, id, introduction, profileImgUrls, userNo,isFollowedByMe }) => (
<FollowUserCard
key={id}
nickName={nickname}
userId={id}
userPk={userNo}
isFollowedByMe={isFollowedByMe}
imageUrl={profileImgUrls[0]?.attachUrl}
content={introduction}
/>
Expand Down
1 change: 1 addition & 0 deletions client/src/types/user/followingUserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface FollowingUserInterface {
id: string;
userNo: number;
introduction: string;
isFollowedByMe:boolean;
createdBy: number;
profileImgUrls: AttachInterface[];
}
Expand Down

0 comments on commit bb113ad

Please sign in to comment.