Skip to content

Commit 76c87b4

Browse files
authored
Merge pull request #175 from 100-hours-a-week/173/fix/게시글_수정시_이미지_업로드_오류
fix: 게시글 수정/삭제 시 오류 수정
2 parents 0dc6f7a + 587e0e3 commit 76c87b4

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/api/queries/postQueries.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "../post";
1919
import {
2020
infiniteQueryOptions,
21+
QueryClient,
2122
queryOptions,
2223
UseMutationOptions,
2324
} from "@tanstack/react-query";
@@ -92,15 +93,20 @@ export const postQueries = {
9293

9394
delete: ({
9495
postId,
95-
navigate,
96+
queryClient,
9697
}: {
9798
postId: number;
98-
navigate: NavigateFunction;
99+
queryClient: QueryClient;
99100
}) => ({
100101
mutationKey: [...postQueries.all(), "delete", postId],
101102
mutationFn: () => deletePost(postId),
102103
onSuccess: () => {
103-
navigate("/");
104+
queryClient.invalidateQueries({
105+
queryKey: [...postQueries.all(), "list"],
106+
});
107+
queryClient.invalidateQueries({
108+
queryKey: [...postQueries.all(), "userPostList"],
109+
});
104110
},
105111
onError: (error: AxiosError<IError>) => {
106112
if (error.response?.status !== 401) {

src/components/common/PostCard/ContextMenu.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { useState } from "react";
22
import { Button } from "../../ui/button";
33
import { useNavigate } from "react-router-dom";
4-
import { useMutation } from "@tanstack/react-query";
4+
import { useMutation, useQueryClient } from "@tanstack/react-query";
55
import { postQueries } from "@/api/queries/postQueries";
66

77
export default function ContextMenu({ postId }: { postId: number }) {
88
const navigate = useNavigate();
9+
const queryClient = useQueryClient();
910
const [isOpen, setIsOpen] = useState<boolean>(false);
1011
const { mutate: deletePost } = useMutation({
11-
...postQueries.delete({ postId, navigate }),
12+
...postQueries.delete({ postId, queryClient }),
1213
});
1314

1415
const handleKeyDown = (e: React.KeyboardEvent) => {

src/hooks/common/useImageUpload.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export const useImageUpload = () => {
4343
try {
4444
const imageUrls = await Promise.all(
4545
selectedImages.map(async (image) => {
46+
if (image.file.size === 0 && image.preview.startsWith("http")) {
47+
return image.preview;
48+
}
49+
4650
const imageUrl = await uploadImageToS3(image.file);
4751
return imageUrl;
4852
}),

0 commit comments

Comments
 (0)