Skip to content

Commit

Permalink
Refactor: 짤 상세 모달 컴포넌트 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjinan096 committed Mar 8, 2024
1 parent e18c380 commit c5432b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/ImageDetailModal/ButtonWithIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ButtonWithIcon = ({
{!isLoading && <Icon aria-label={iconLabel} />}
{isLoading && (
<div className="h-6 w-6">
<span className="loading loading-spinner loading-xs"></span>
<span className="loading loading-spinner loading-xs" />
</div>
)}
<span className="mt-1 hidden text-xs sm:flex">{children}</span>
Expand Down
14 changes: 4 additions & 10 deletions src/components/ImageDetailModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ const ImageDetailModalContent = () => {
const { reportZzal } = usePostReportZzal();
const { deleteMyZzal } = useDeleteMyZzal();
const reportConfirmOverlay = useOverlay();
const {
imageLikeYn: isLiked,
imgUrl: imageUrl,
tags,
imageTitle,
uploadUserId,
imageId,
} = zzalDetails;
const { isLiked, imageUrl, tags, imageTitle, uploadUserId, imageId } = zzalDetails;

const isUploader = uploadUserId === 19;
//TODO: [2024.03.01] 추후 실제 사용자 아이디와 비교하기
Expand Down Expand Up @@ -67,13 +60,14 @@ const ImageDetailModalContent = () => {

deleteMyZzal(imageId, {
onSuccess: () => {
setIsDeleting(false);
toast.success("사진이 삭제되었습니다.");
},
onError: () => {
setIsDeleting(false);
toast.error("사진 삭제에 실패했습니다.");
},
onSettled: () => {
setIsDeleting(false);
},
}); // TODO: [2024-03-05] 모달 클릭 시 URL이 변경되도록 구현 후, 이미지 삭제 성공 시 이전 페이지로 이동하는 navigate 추가 필요
}, 500);

Expand Down
5 changes: 5 additions & 0 deletions src/hooks/api/zzal/useGetZzalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const useGetZzalDetails = (imageId: number) => {
const { data: zzalDetails, ...rest } = useSuspenseQuery({
queryKey: ["zzalDetails", imageId],
queryFn: () => getZzalDetails(imageId),
select: (data) => ({
isLiked: data.imageLikeYn,
imageUrl: data.imgUrl,
...data,
}),
});
return { zzalDetails, ...rest };
};
Expand Down

0 comments on commit c5432b7

Please sign in to comment.