-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: useOnClickBlock hook 구현 - 드래그 중인 경우 클릭이 발생하지 않도록 한다. * refactor: MiniRestaurantCard 컴포넌트 useOnClickBlock 적용 * refactor: CelebProfile 컴포넌트 생성 및 useOnClickBlock 적용 * refactor: BannerSlider 컴포넌트 useOnClickBlock 적용
- Loading branch information
1 parent
d2ac638
commit 063ee73
Showing
6 changed files
with
113 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import styled from 'styled-components'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { Celeb } from '~/@types/celeb.types'; | ||
import { FONT_SIZE } from '~/styles/common'; | ||
import ProfileImage from '../@common/ProfileImage'; | ||
import useOnClickBlock from '~/hooks/useOnClickBlock'; | ||
|
||
function CelebProfile({ name, profileImageUrl, id }: Celeb) { | ||
const navigate = useNavigate(); | ||
const register = useOnClickBlock({ | ||
callback: () => navigate(`/celeb/${id}`), | ||
}); | ||
|
||
return ( | ||
<StyledCeleb {...register}> | ||
<ProfileImage name={name} imageUrl={profileImageUrl} size="64px" boxShadow /> | ||
<span>{name}</span> | ||
</StyledCeleb> | ||
); | ||
} | ||
|
||
export default CelebProfile; | ||
|
||
const StyledCeleb = styled.div` | ||
display: flex !important; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 0.8rem; | ||
font-size: ${FONT_SIZE.sm}; | ||
cursor: pointer; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import CelebProfile from './CelebProfile'; | ||
|
||
export default CelebProfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useCallback, useState } from 'react'; | ||
|
||
interface UseOnClickBlockProps { | ||
callback: () => void; | ||
} | ||
|
||
const useOnClickBlock = ({ callback }: UseOnClickBlockProps) => { | ||
const [isDragging, setIsDragging] = useState<boolean>(false); | ||
|
||
const handleMouseDown = useCallback(() => { | ||
setIsDragging(false); | ||
}, []); | ||
|
||
const handleMouseMove = useCallback(() => { | ||
setIsDragging(true); | ||
}, []); | ||
|
||
const handleClick = () => { | ||
if (isDragging) return; | ||
callback(); | ||
}; | ||
|
||
return { onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onClick: handleClick }; | ||
}; | ||
|
||
export default useOnClickBlock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters