Skip to content

[URH-67] usePreventCopy 신규 #50

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

Merged
merged 3 commits into from
Sep 6, 2024
Merged

[URH-67] usePreventCopy 신규 #50

merged 3 commits into from
Sep 6, 2024

Conversation

bicochan
Copy link
Member

👾 Pull Request

1️⃣ Spec

  • 브라우저에서 복사 이벤트 발생 시 이벤트를 차단하고 콜백 함수를 실행합니다.

2️⃣ 변경 사항

없음

3️⃣ 예시 코드

function App() {
  const callbackCopy = () => {
    alert('복사할 수 없습니다.');
  };

  usePreventCopy(callbackCopy);

  return (
    <div>
      <h1>USE-REACT-HOOKS</h1>
    </div>
  );
}

@bicochan bicochan requested a review from jeongbaebang August 19, 2024 02:02
Copy link
Collaborator

@foresec foresec left a comment

Choose a reason for hiding this comment

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

깔끔하게 작성하셨군요 수고하셨습니다!👍

Comment on lines +10 to +11
const usePreventCopy = (callback?: () => void) => {
const preventCopy = (e: ClipboardEvent) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[P3] 일단 처음에 백로그에 의견을제시했을때는 preventCopy라고 작성하긴 했는데... copy와 cut 모두를 차단한다는 점에서 이름을 조금 바꿔볼 필요가 있을까 싶어지네요

Copy link
Collaborator

Choose a reason for hiding this comment

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

[P3] 또한, boolean값 매개변수를 통해 조건부터 해당 이벤트를 차단하게 하면 조금 더 유연한 훅이 될 수 있지 않을까요? 디폴트는 true를 주고요. 정확하게 용도가 떠오르진 않지만 회원이면 복/잘 가능 비회원이면 복/잘 불가능 이렇게...
물론 꼭 추가되어야하는 필수 기능은 아니라고 생각합니다ㅋㅋㅋ

Copy link
Member Author

Choose a reason for hiding this comment

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

좋은 의견 감사해요 소현 님!

  • 소현 님 의견을 듣고 나니 copycut을 함께 차단할 필요가 없을 것 같다는 생각이 들기도 하네요. cut 이벤트가 발생하는 상황은 사용자에게 이미 write 권한이 주어진 상황일텐데 그런 상황에서는 굳이 막을 필요가 없다는 생각이 들었습니다. usePreventCopyusePreventCut을 분리하는 건 어떻게 생각하실까요?
  • callback 활성화 여부는 생각하지 못한 부분인데 짚어주셔서 감사해요! 그런데 callback 활성화 여부는 외부에서 처리하는 게 좀 더 명확하지 않을까요? 현재 상태(as-is)와 소현 님이 말씀해주신 상태(to-be)를 비교해보았는데 usePreventCopy 훅은 copy 이벤트를 차단하는 역할만 가져가게 하고 싶기도 하네요!
// as-is
isAuth && usePreventCopy(callback)

// to-be
usePreventCopy(callback, isAuth)

Copy link
Collaborator

Choose a reason for hiding this comment

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

  • 앗 저는 반대로usePreventClipboard와 같이 합쳐진 상태에서 이름을 바꿔야하는 게 아닐까 하여 제안드린거였는데 그렇게 바꿀 수도 있네요. 분리한다는 게 나쁘진 않지만 그럼 훅의 기능의 크기(?)가 너무 작아지지 않나하는 생각도 듭니다.
  • 알려주신 대로 외부에서 처리하는 방식도 좋아보입니다. 꼭 변수를 넘겨주면서 관리할 필요는 없으니까요

Copy link
Member Author

@bicochan bicochan Sep 5, 2024

Choose a reason for hiding this comment

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

저도 usePreventClipboard로 훅을 재정의하는 것을 생각해봤는데 사용자가 useClipboard를 차단하는 기능으로 오해하진 않을까 하는 생각도 같이 들었습니다. copy와 cut 이벤트는 clipboard 이벤트와는 별개의 로직이더라구요. 그래도 소현 님이 말씀해주신 방향엔 저도 동의를 해서 해당 내용은 리팩토링 시에 진행해 보겠습니다!

이 PR의 오픈 기간이 오래되어서 일단 머지를 한 번 하는 게 좋을 것 같네요. 혹시 또 다른 내용이 없다면 승인 한 번 부탁드려도 될까요?☺️

Copy link
Member

@jeongbaebang jeongbaebang left a comment

Choose a reason for hiding this comment

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

👍

@bicochan bicochan changed the title [URH-67] usePreventCopy 신규(테스트 코드 작성중) [URH-67] usePreventCopy 신규 Sep 2, 2024
Copy link
Collaborator

@foresec foresec left a comment

Choose a reason for hiding this comment

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

수고하셨습니다😀👍

@bicochan bicochan merged commit d84fcf5 into master Sep 6, 2024
4 checks passed
@bicochan bicochan deleted the URH-67/use-prevent-copy branch September 6, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants