Skip to content

Commit eaab5ce

Browse files
authored
Merge pull request #42 from happbob/feat/OD-1
Feat: 매칭 요청이 없을 때 홈>매칭 탭 비활성화
2 parents 8e679d3 + defa96e commit eaab5ce

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/pages/Home/HomeTabBar.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ const HomeTabBar: React.FC<HomeTabBarProps> = ({ onOpenBottomSheet }) => {
4545
};
4646

4747
const handleSwiperChange = (swiper: SwiperCore) => {
48-
setActiveIndex(swiper.activeIndex);
48+
// 매칭 요청이 없고 1번 index에 있을 때 0번 탭 비활성화
49+
if (!hasMatchingRequests && swiper.activeIndex === 1) {
50+
console.log(1);
51+
swiper.allowSlidePrev = false;
52+
setActiveIndex(swiper.activeIndex);
53+
}
54+
// 매칭 요청이 있을 때 양쪽 스와이퍼 가능
55+
else {
56+
console.log(3);
57+
swiper.allowSlidePrev = true;
58+
setActiveIndex(swiper.activeIndex);
59+
}
4960
};
5061

5162
const fetchMatchingRequests = async () => {
@@ -100,6 +111,7 @@ const HomeTabBar: React.FC<HomeTabBarProps> = ({ onOpenBottomSheet }) => {
100111
swiperRef.current = swiper;
101112
}}
102113
onSlideChange={handleSwiperChange}
114+
allowSlidePrev={hasMatchingRequests}
103115
spaceBetween={0}
104116
slidesPerView={1}
105117
autoHeight={true}
@@ -109,7 +121,13 @@ const HomeTabBar: React.FC<HomeTabBarProps> = ({ onOpenBottomSheet }) => {
109121
<SwiperSlide
110122
style={{ height: 'auto', visibility: hasMatchingRequests && isMatchingReady ? 'visible' : 'hidden' }}
111123
>
112-
<Matching tooltipRef={cardRef} />
124+
<Matching
125+
tooltipRef={cardRef}
126+
swipeToOOTD={() => {
127+
setHasMatchingRequests(false);
128+
swiperRef.current?.slideNext();
129+
}}
130+
/>
113131
</SwiperSlide>
114132
<SwiperSlide style={{ height: 'auto' }}>
115133
<OOTD tooltipRef={ootdTooltipRef} onMoreClick={onOpenBottomSheet} />

src/pages/Home/Matching/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ interface Relationship {
1010
requestStatus: string; // 추가된 필드
1111
}
1212

13-
const Matching: React.FC<{ tooltipRef: React.MutableRefObject<HTMLDivElement | null> }> = ({ tooltipRef }) => {
13+
interface MatchingProps {
14+
tooltipRef: React.MutableRefObject<HTMLDivElement | null>;
15+
swipeToOOTD: () => void;
16+
}
17+
18+
const Matching: React.FC<MatchingProps> = ({ tooltipRef, swipeToOOTD }) => {
1419
const [matchingCount, setMatchingCount] = useState<number>(0);
1520

1621
useEffect(() => {
@@ -33,7 +38,11 @@ const Matching: React.FC<{ tooltipRef: React.MutableRefObject<HTMLDivElement | n
3338

3439
// 매칭 요청이 제거되었을 때 호출되는 함수
3540
const handleRemoveMatching = () => {
36-
setMatchingCount((prevCount) => Math.max(0, prevCount - 1));
41+
if (matchingCount !== 1) {
42+
setMatchingCount((prevCount) => Math.max(0, prevCount - 1));
43+
} else {
44+
swipeToOOTD();
45+
}
3746
};
3847

3948
return (

0 commit comments

Comments
 (0)