-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 이스터에그 토스트 사용성 개선 및 hook 디렉토리 이동 (#527)
* feat: 페이지 이동 시 렌더링중인 토스트 제거 * refactor: 토스트 발생 높이 재조정 * refactor: easterEgg 로직과 컴포넌트 분리 * refactor: hooks/common > hooks/@common으로 이동
- Loading branch information
Showing
15 changed files
with
98 additions
and
67 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
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
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
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,38 @@ | ||
import { useState } from 'react'; | ||
|
||
import { useToast } from '@/context/Toast/ToastContext'; | ||
|
||
const AWAKE_NUMBER = 10; | ||
const DANGER_NUMBER = AWAKE_NUMBER - 1; | ||
|
||
let startTime: Date | undefined; | ||
let endTime: Date | undefined; | ||
|
||
const calcDuration = () => (Number(endTime) - Number(startTime)) / 1000; | ||
|
||
const useEasterEgg = () => { | ||
const { toast } = useToast(); | ||
|
||
const [dogTouchCount, setDogTouchCount] = useState(1); | ||
const isDogAwake = dogTouchCount > AWAKE_NUMBER; | ||
|
||
const onTouchDog = () => { | ||
if (dogTouchCount === AWAKE_NUMBER && startTime) { | ||
endTime = new Date(); | ||
|
||
toast.success(`${calcDuration()}초 만에 강아지를 깨웠어요!`); | ||
} else if (dogTouchCount === DANGER_NUMBER) { | ||
toast.warning('강아지를 깨우지 않게 조심하세요!'); | ||
} else if (dogTouchCount < AWAKE_NUMBER) { | ||
startTime = startTime ?? new Date(); | ||
|
||
toast.info(`강아지를 ${dogTouchCount}번 쓰다듬었어요.`); | ||
} | ||
|
||
if (dogTouchCount <= AWAKE_NUMBER) setDogTouchCount(prev => prev + 1); | ||
}; | ||
|
||
return { onTouchDog, isDogAwake }; | ||
}; | ||
|
||
export default useEasterEgg; |
File renamed without changes.
File renamed without changes.
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
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
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