Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#81] Feat: 짤 이미지 삭제 api 연결 및 성공/삭제 시 동작 구현 #86

Merged
merged 10 commits into from
Mar 5, 2024

Conversation

HY219
Copy link
Contributor

@HY219 HY219 commented Mar 3, 2024

📝 작업 내용

  • 짤 이미지 삭제 api 연결
    • /v1/image/${imageId} - DELETE
  • 성공/삭제 시 Toast 띄우기
    • toastify 이용
  • 성공 시 모달 닫히는 동작 구현
    • Context API 이용
    • 모달 컨텍스트를 사용하지 않고, onSuccess 콜백 이용

📷 스크린샷 (선택)

💬 리뷰 요구사항(선택)

+추가로 궁금한 사항이 있습니다!

  • 서버에서 imageId를 int값으로 전달 받는데, url일 경우 string으로 지정해줘야하나요?
    현재 코드에서는 number로 받고 있는데, string으로 변경해줘야하는지 궁금합니다!
    export const deleteMyZzal = (imageId: number) => {
      return http.delete<number>({ url: `/v1/image/${imageId}` });
    };
    

다음과 같이 에러가 뜨는데, 캐시 무효화 문제인지, 배포 ID 문제인지 해결이 어려워 도움 요청합니다.
image

📍 기타 (선택)

  • TODO: 홈 화면 등 페이지 구현 시, 짤 이미지 삭제 성공 시 페이지 새로고침 필요 쿼리 무효화 필요
  • TODO: 이미지 상세 모달 구현 시, 유저 본인이 업로드한 이미지가 아닐 경우 삭제 버튼 비활성화 구현 필요
  • TODO: [2024-03-03] 이미지 상세 모달 구현 코드에 따라 변경될 수 있습니다. (이미지 삭제 성공 시, 모달이 닫히는 동작을 구현하기 위해 코드 구현) -> 짤 클릭 시 모달 열고 닫는 코드

close #81

HY219 added 2 commits March 1, 2024 21:38
useMutation을 이용
/v1/image/ url로 삭제 요청
TODO: 이미지 상세보기 api 연결 후, 실제 imageId 전달해야합니다.
TODO: 삭제 API 요청이 성공하면, 모달을 닫고 페이지를 새로고침해야합니다.
toastify 사용
짤 이미지 삭제 성공 시 모달 자동으로 닫히도록 구현
TODO: 짤 이미지 삭제 성공 시 페이지 새로고침
TODO: 이미지 상세 모달 구현 시, 유저 본인이 업로드한 이미지가 아닐 경우 삭제 버튼 비활성화 구현 필요
Copy link

vercel bot commented Mar 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zzalmyu-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2024 2:59pm

@HY219 HY219 self-assigned this Mar 3, 2024
@HY219 HY219 added the ✨ Feature 새로운 기능 추가 label Mar 3, 2024
@HY219 HY219 force-pushed the #81/feature/delete-my-zzal-api branch 2 times, most recently from d5bf0a3 to d527ac1 Compare March 3, 2024 08:57
@Kim-Jaemin420
Copy link
Contributor

삭제시, 새로고침이 필요한건 아닐거예요! 삭제 성공후 querykey invalidate 시켜주면 아마 원하시는대로 동작하지 않을까 합니다. 한 번 알아보고 적용해주세요!

@HY219
Copy link
Contributor Author

HY219 commented Mar 3, 2024

삭제시, 새로고침이 필요한건 아닐거예요! 삭제 성공후 querykey invalidate 시켜주면 아마 원하시는대로 동작하지 않을까 합니다. 한 번 알아보고 적용해주세요!

감사합니다 😀

혹시 invalidateQueries로 쿼리 무효화하는 거 말씀하시는 건가요?

삭제 성공 후 쿼리를 무효화하는 걸 말씀하시는게 맞다면, 홈, 업로드한 짤, 좋아요한 짤 페이지에 API가 연결되고 쿼리키가 생성된 후에 쿼리 무효화 코드를 추가할 수 있을 것 같아서 TODO로 두었습니다!

위 코드가 구현된 후에 추가할 수 있을 것 같은데 어떻게 생각하시나요?

@Kim-Jaemin420
Copy link
Contributor

@HY219 넵 맞습니다! 새로고침으로 표현해주셔서 잘못 이해하고 계신 줄 알고 팁을 드렸습니다ㅎㅎ 어차피 업로드한 짤과 좋아요한 짤은 페이지 진입시에 재요청하니 굳이 invalidate 해줄 필요는 없을 것 같습니다~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미지 상세 모달 UI가 변경되면서 ImageMenuBar가 제거되고 index에 버튼이 다 모인 구조로 변경되었습니다. 위치만 바뀐 거여서 나중에 코드가 옮겨질 수 있을 것 같네요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 감사합니다! 그럼 이미지 상세 모달 UI가 머지된 후에 코드 수정 후 머지하는게 좋겠네요:)

@HY219
Copy link
Contributor Author

HY219 commented Mar 4, 2024

@HY219 넵 맞습니다! 새로고침으로 표현해주셔서 잘못 이해하고 계신 줄 알고 팁을 드렸습니다ㅎㅎ 어차피 업로드한 짤과 좋아요한 짤은 페이지 진입시에 재요청하니 굳이 invalidate 해줄 필요는 없을 것 같습니다~

제가 표현을 잘 못 쓴 것 같네요! 🤣

모달이 닫히는 경우에 페이지에 진입하는 걸 알 수 있나요?

같은 url 창에서 모달을 열었다 닫았을 때 진입해 있던 페이지에 영향을 주거나, 재진입했다고 인식하지 못할 것 같은데 어떻게 생각하시나요?

TODO: 모달 클릭 시 URL이 변경되도록 구현 후, 이미지 삭제 성공 시 이전 페이지로 이동하는 navigate 추가
const [isLiked, setIsLiked] = useState(false);

const handleClickLike = () => {
setIsLiked((prevLiked) => !prevLiked);
};

const { deleteMyZzal } = useDeleteMyZzal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api 커스텀 훅은 상단에 위치시키면 더 잘 보일 거 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 👍 놓쳤네요 감사합니다!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 api 훅은

  1. 관리자 페이지에서 신고 사진을 삭제하는 기능인가요
  2. 이미지 상세 모달에서 본인 사진을 삭제하는 기능인가요?
    만약 2번이라면 디렉토리 구조 수정하셔야 할 것 같습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 그러네요...ㄷㄷㄷ머지될뻔

const { mutate, ...rest } = useMutation({
mutationFn: deleteMyZzal,
onSuccess: () => {
toast.success("사진이 삭제되었습니다.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[내 사진 삭제] 후 masonry layout의 사진들은 업데이트가 되나요?
invalidateQueriessetQueryData로 캐시 업데이트를 해야 할 것 같은데 어떻게 생각하시나요?
아래 시나리오를 적어봤는데 혹시 아래와 같은 상황이 발생한다면 invalidateQueries로 한번 다시 데이터를 받아오는 게 좋을 것 같습니다
[시나리오]
본인이 올린 사진 A를 홈의 masonry layout에서 클릭해서 이미지 상세 모달로 이동 -> 모달에서 사진 삭제 성공 -> 모달 닫히고, 다시 홈의 masonry layout으로 이동 -> 이때 masonry layout의 사진들은 이미지 삭제하기 전의 캐시라 방금 삭제한 이미지가 보인다

Copy link
Contributor

@yjc2021 yjc2021 Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO 사항이군요~ 네버마인드 :)
TODO 주석 달아주세요!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSuccess와 onError에 관한 코드 ImageMenuBar 파일로 위치 변경해줬습니다! useDeleteMyZzal에서 onSuccess를 중복으로 작성하지 않아도 될 것 같았습니다:)

Copy link
Contributor

@yjc2021 yjc2021 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 입니다~ 💯 '

Copy link
Contributor

@Kim-Jaemin420 Kim-Jaemin420 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 LGTM 입니닷!

@HY219 HY219 merged commit 661688d into main Mar 5, 2024
3 checks passed
@HY219 HY219 deleted the #81/feature/delete-my-zzal-api branch March 5, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 새로운 기능 추가
Projects
None yet
Development

Successfully merging this pull request may close these issues.

짤 이미지 삭제 api 연결
4 participants