Skip to content

Commit

Permalink
Merge pull request #70 from potenday-project:수정,삭제-드롭다운-컴포넌트-분리
Browse files Browse the repository at this point in the history
수정,삭제-드롭다운-컴포넌트-분리
  • Loading branch information
jobkaeHenry authored Dec 4, 2023
2 parents 75b00ea + 11f89bf commit ffa54e6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Client-DEV-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fetch-depth: 0

- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v1.6.0
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { ButtonBase, Menu, MenuItem } from "@mui/material";
import { MoreVertOutlined } from "@mui/icons-material";
import { useState } from "react";

interface PostCommentDropdownInterface {
onDelete: () => void;
onEdit: () => void;
interface DeleteEditDropdownInterface {
onDelete?: () => void;
onEdit?: () => void;
}

const PostCommentDropdown = ({
const DeleteEditDropdown = ({
onDelete,
onEdit,
}: PostCommentDropdownInterface) => {
}: DeleteEditDropdownInterface) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);

Expand All @@ -35,4 +35,4 @@ const PostCommentDropdown = ({
);
};

export default PostCommentDropdown;
export default DeleteEditDropdown;
20 changes: 19 additions & 1 deletion client/src/components/post/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ import "../newpost/quill.mention.css";
import { sanitize } from "isomorphic-dompurify";
import UserAvatar from "../user/info/UserAvatar";
import Link from "next/link";
import { USER_PAGE } from "@/const/clientPath";
import HOME, { USER_PAGE } from "@/const/clientPath";
import { useMyInfoQuery } from "@/queries/auth/useMyInfoQuery";
import PostCardOptionDropdown from "./PostCardOptionDropdown";
import { postcardContext } from "@/store/post/PostCardContext";
import { useDeletePostMutation } from "@/queries/post/useDeletePostMutation";
import useDeleteAttachMutation from "@/queries/attach/useDeleteAttachMutation";
import { useRouter } from "next/navigation";

const PostCard = ({
postAttachUrls,
Expand All @@ -49,12 +52,27 @@ const PostCard = ({
alcoholNo,
}: PostInterface) => {
const openPostDetailPage = useOpenPostDetailPage();
const router = useRouter();

const hasImage = useMemo(() => postAttachUrls.length !== 0, [postAttachUrls]);

const searchContext = useContext(postcardContext);

const { mutate: likeHandler } = useLikePostMutation(searchContext);
const { mutate: unLikeHandler } = useUnLikePostMutation(searchContext);

const { mutateAsync: deletePost } = useDeletePostMutation();
const { mutateAsync: deleteFile } = useDeleteAttachMutation();

const deleteHandler = async () => {
if (confirm("정말 삭제하시겠습니까?")) {
await deletePost(postNo);
postAttachUrls?.[0].attachUrl &&
(await deleteFile(postAttachUrls?.[0].attachUrl));
router.push(HOME);
}
};

const { data: currentUser } = useMyInfoQuery();

const isMyPost = useMemo(
Expand Down
22 changes: 2 additions & 20 deletions client/src/components/post/PostCardOptionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDeletePostMutation } from "@/queries/post/useDeletePostMutation";
import useDeleteAttachMutation from "@/queries/attach/useDeleteAttachMutation";
import { useRouter } from "next/navigation";
import HOME from "@/const/clientPath";
import DeleteEditDropdown from "../DeleteEditDropdown";

type PostCardOptionDropdownProps = {
postId: number;
Expand All @@ -15,13 +16,7 @@ const PostCardOptionDropdown = ({
postId,
filePk,
}: PostCardOptionDropdownProps) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const router = useRouter();

const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const { mutateAsync: deletePost } = useDeletePostMutation();
const { mutateAsync: deleteFile } = useDeleteAttachMutation();

Expand All @@ -33,20 +28,7 @@ const PostCardOptionDropdown = ({
}
};

const handleClose = () => {
setAnchorEl(null);
};
return (
<>
<ButtonBase aria-label="settings" sx={{ p: 0 }} onClick={handleClick}>
<MoreVertOutlined />
</ButtonBase>
<Menu open={open} anchorEl={anchorEl} onClose={handleClose}>
<MenuItem onClick={deleteHandler}>삭제</MenuItem>
<MenuItem>수정</MenuItem>
</Menu>
</>
);
return <DeleteEditDropdown onDelete={deleteHandler} />;
};

export default PostCardOptionDropdown;
11 changes: 5 additions & 6 deletions client/src/components/post/detail/PostComment.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import UserAvatar from "@/components/user/info/UserAvatar";
import { USER_PAGE } from "@/const/clientPath";
import { useMyInfoQuery } from "@/queries/auth/useMyInfoQuery";
import { Stack, Avatar, Typography } from "@mui/material";
import { Stack, Typography } from "@mui/material";
import dayjs from "dayjs";
import Link from "next/link";
import PostCommentDropdown from "./PostCommentDropdown";
import DeleteEditDropdown from "@/components/DeleteEditDropdown";
import useDeleteCommentMutation from "@/queries/post/comment/useDeleteCommentMutation";

type Props = {
Expand All @@ -31,7 +31,7 @@ const PostComment = ({
const { data: myData } = useMyInfoQuery();

const isMyComment = userPk === String(myData?.userNo);
const { mutateAsync: onDelete } = useDeleteCommentMutation();
const { mutateAsync: deleteHandler } = useDeleteCommentMutation();

return (
<Stack direction="row" width="100%" gap={1.25}>
Expand All @@ -57,14 +57,13 @@ const PostComment = ({
</Typography>
</Stack>
{isMyComment && (
<PostCommentDropdown
<DeleteEditDropdown
onDelete={() => {
onDelete({
deleteHandler({
commentPk: String(commentPk),
postPk: String(postPk),
});
}}
onEdit={() => {}}
/>
)}
</Stack>
Expand Down

0 comments on commit ffa54e6

Please sign in to comment.