-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feat/#333 refactor custom hook #334
base: release/2.1.1
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼👍🏼👍🏼👍🏼
근데 knob, useDrawer가 뭥가요????(궁금)
export default function MenuModal(props: MenuModalProps) { | ||
const { currentCardId, closeHandler, autoSlide, handleClickAddBlacklist, handleClickCancelBlacklist } = props; | ||
const { showToast, blackoutToast } = useToast(); | ||
|
||
const { isShow: isBlockShow } = useShowByCardType([LocationType.BEST, LocationType.MEDLEY]); | ||
const { cardType } = useCardType(); | ||
const [isBlockShow, setIsBlockShow] = useState<boolean>(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isBlockShow 뭔가 어법이 이상한 듯한 느낌이...?
-> isBlockShown or couldShowBlock or ... 어떨까 싶어요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다시보니 그러네요! isBlockVisible
은 어떤가요?
@@ -23,11 +25,18 @@ type ModalItem = { | |||
gtmClassName: string; | |||
}; | |||
|
|||
const locationTypesNoBlock = [LocationType.BEST, LocationType.MEDLEY]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요런 것도 이 const 배열 객체의 정체성은 'location types' 이므로,
이름이 noBlockLocationTypes
가 되는 게 적절해보여요
혹은 locationTypesForNoBlock
처럼 for를 붙여 특수성을 나타내거나?
(+ locationTypesNoReplay 변수명도 동일)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 의견입니다! no
를 앞에 붙여 명시하는게 좋을것 같아요
const page = dragDirection === "X" ? event.pageX : event.pageY; | ||
currentRef.current = page; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼👍🏼
@@ -1,40 +1,47 @@ | |||
import { useRef, useState } from "react"; | |||
|
|||
export default function useDraggingContainer() { | |||
type DragDirectionType = "X" | "Y"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'horizon'도 아닌, 'x'도 아닌, 'X'인 이유가 있을까요?
추상화 레벨 적절하게 열어진 것 다 좋은데, 이 인자값 인터페이스가 조금 어색해보여요
타이핑도 되어있고 해서 지금 상태도 괜찮지만, 가능하다면 좀 더 일반적으로 기대 가능한 인터페이스면 어떨까 싶습니다!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
읽는 사람들(개발자들)에게 x/y
는 'x축', 'y축'이라는 통용된 개념으로 읽히기 때문에 horizon/vertical
으로 굳이 길게 늘릴 필요가 없다고 생각했어요!
x/y와 X/Y 중 고민했는데, 속성명 중에 pageX, pageY가 있기 때문에 통일성을 주기 위해 X, Y를 사용했습니다.
x/y가 좀 더 가독성이 낫다고 느끼신다면 고쳐보겠습니다!
function handleMouseDown(event: React.MouseEvent<HTMLElement, MouseEvent>) { | ||
function handleMouseDown(event: React.SyntheticEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아예 터치 핸들러 따로 만드는 게 좀 더 적절하지 않을까 하는 생각?
function handleMouseDown(event: React.MouseEvent<HTMLElement, MouseEvent>) { | ||
function handleTriggerDown(event: React.SyntheticEvent<HTMLElement>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
X, Y를 한 훅에서 처리하는 건 적절해보이는데,
마우스 동작과 터치 동작을 한 함수로 묶는 건 좀 과해보여요
이후에 마우스, 터치 로직들이 추가되고 한다면 함수가 하나의 동작을 못하게 되고 다시 분리하게 되는 현상이 일어날 것 같아서,
차라리 Touch Hanlder 함수를 따로 파주는 게 나을 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 고민했던 부분인데, MouseDown과 TouchDown 핸들러의 로직이 완전히 동일하기도 해서, 훅 내부가 장황해지는 것을 우려했던 것 같아요. 그래도 아래와 같이 분리하는 게 좋을까요?
function handleMouseDown(event: React.MouseEvent<HTMLElement>) {
setIsStartDragging(true);
const page = getPageByEventType(event);
currentRef.current = page;
initializeForDragged(page);
}
function handleTouchDown(event: React.TouchEvent<HTMLElement>) {
setIsStartDragging(true);
const page = getPageByEventType(event);
currentRef.current = page;
initializeForDragged(page);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 분리하는 게 좋아보입니다!
내용이 많으면 내부 코드가 길어지는 건 당연한거지만, 함수간의 목적성이 흐려지는 건 분명한 안티패턴이니까요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 분리하겠습니다! 감사해요:)
Y: "pageY", | ||
}; | ||
|
||
const FIRST_TOUCH = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more specific naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
터치이벤트가 여러개 발생할 수 있는데, 그 중 첫번째만 사용하고 있으므로 이부분을 인덱스로 따로 뺌
=> FIRST_TOUCH_EVENT_IDX
로 변경하겠습니다!
const [isStartDragging, setIsStartDragging] = useState<boolean>(false); | ||
const [dragged, setDragged] = useState<number>(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
중복 타이핑
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떤 부분이 중복이죠?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false, 0으로 초기값 설정하면 타입추론이 될텐데, boolean, number로 한 겹 더 타입을 지정하는 건 되려 휴먼에러를 일으키지 않을까 해서🤔 저는 추론 될 때는 타입 지정을 안 하는 편이에요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 한번도 생각못해본 거예요. 무작정 타입 지정해주는게 좋다고 생각했었는데! 감사합니다
const currentRef = useRef(0); | ||
const standardRef = useRef(0); | ||
|
||
const [isStartDragging, setIsStartDragging] = useState<boolean>(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDragging
?
const standardRef = useRef(0); | ||
|
||
const [isStartDragging, setIsStartDragging] = useState<boolean>(false); | ||
const [dragged, setDragged] = useState<number>(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more specific naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
draggedDistance
로 변경하겠습니다!
역시 빠르다 은형!!!!🙆♂️👏 |
@joohaem |
📌 내용
useShowByQuery
를 삭제하고,useCardType
을 사용하도록 고칩니다. 기존에useShowByQuery
를 쓰던 컴포넌트들은useCardType
을 사용하되,isShow~
state를 사용해 보이지 않아야할 Location들에 따라 state를 변경해주고 있습니다.useDraggableYContainer
를 삭제하고,useDraggingContainer
가 x축 y축 모든 방향에서 스크롤 가능하도록 변경하였습니다. 이 과정에서, 모바일에는 MouseEvent가 적용되지 않음을 알았습니다. 따라서 handler 함수에서는 Synthetic Event로 모두 받되,getPageByEventType
에서 분기처리하여 MouseEvent와 TouchEvent를 구분하고, 기존에는onMouse~
로만 전달되고 있던 props에onTouch~
속성을 추가하였습니다.useRecentlyBookmarked
의 위치를 변경하였습니다. 제가 잘못 생각했던 부분이 있는데, "두개 이상의 컴포넌트에서 공통으로 사용한다 = 모두의 공통컴포넌트이다"라고 잘못생각했던 것 같습니다. 앞으로는 이 점 유의하면서 코딩하는게 좋겠습니다!useDrawer
을 리팩토링하였습니다. 로직은useDraggingContainer
와 유사합니다.📌 내가 알게 된 부분
clientX와 pageX의 차이