Skip to content

Commit 1b2d83e

Browse files
feat: useJobPinsBottomNotice hook 구현
1 parent 39186dc commit 1b2d83e

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { useCallback, useEffect, useRef, useState } from 'react';
2+
3+
export const useJobPinsBottomNotice = () => {
4+
const scrollContainerRef = useRef<HTMLDivElement>(null);
5+
const hideTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
6+
const [isBottomNoticeVisible, setIsBottomNoticeVisible] = useState(false);
7+
8+
const showBottomNoticeTemporarily = useCallback(() => {
9+
if (isBottomNoticeVisible) {
10+
return;
11+
}
12+
13+
setIsBottomNoticeVisible(true);
14+
if (hideTimerRef.current) {
15+
clearTimeout(hideTimerRef.current);
16+
}
17+
18+
hideTimerRef.current = setTimeout(() => {
19+
setIsBottomNoticeVisible(false);
20+
hideTimerRef.current = null;
21+
}, 2000);
22+
}, [isBottomNoticeVisible]);
23+
24+
useEffect(() => {
25+
return () => {
26+
if (hideTimerRef.current) {
27+
clearTimeout(hideTimerRef.current);
28+
}
29+
};
30+
}, []);
31+
32+
const handleBottomWheel = useCallback(
33+
(e: React.WheelEvent<HTMLDivElement>) => {
34+
if (e.deltaY <= 0) {
35+
return;
36+
}
37+
38+
const container = scrollContainerRef.current;
39+
if (!container) {
40+
return;
41+
}
42+
43+
const isAtBottom =
44+
container.scrollTop + container.clientHeight >=
45+
container.scrollHeight - 1;
46+
47+
if (isAtBottom) {
48+
showBottomNoticeTemporarily();
49+
}
50+
},
51+
[showBottomNoticeTemporarily]
52+
);
53+
54+
return {
55+
scrollContainerRef,
56+
isBottomNoticeVisible,
57+
handleBottomWheel,
58+
};
59+
};

0 commit comments

Comments
 (0)