-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmatch-list-section.tsx
More file actions
100 lines (87 loc) · 3.27 KB
/
match-list-section.tsx
File metadata and controls
100 lines (87 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { gameQueries } from '@apis/game/game-queries';
import { matchQueries } from '@apis/match/match-queries';
import ButtonCreate from '@components/button/button-create/button-create';
import type { TabType } from '@components/tab/tab/constants/tab-type';
import EmptyView from '@components/ui/empty-view';
import { gaEvent } from '@libs/analytics';
import { renderMatchCards } from '@pages/home/utils/match-card-renderers';
import { ROUTES } from '@routes/routes-config';
import { useQuery } from '@tanstack/react-query';
import { format } from 'date-fns';
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
interface MatchListSectionProps {
activeType: TabType;
isSingle: boolean;
isGroup: boolean;
selectedDate: Date;
onOpenGameInfoBottomSheet: () => void;
}
const MatchListSection = ({
isSingle,
isGroup,
selectedDate,
onOpenGameInfoBottomSheet,
}: MatchListSectionProps) => {
const navigate = useNavigate();
const formattedDate = format(selectedDate, 'yyyy-MM-dd');
const { data: singleMatchData } = useQuery({
...matchQueries.SINGLE_MATCH_LIST(formattedDate),
enabled: isSingle,
});
const { data: groupMatchData } = useQuery({
...matchQueries.GROUP_MATCH_LIST(formattedDate),
enabled: isGroup,
});
const { data: gameSchedule, isLoading: gameLoading } = useQuery({
...gameQueries.GAME_LIST(formattedDate),
});
const filteredMatches = useMemo(() => {
return isSingle ? (singleMatchData?.mates ?? []) : (groupMatchData?.mates ?? []);
}, [isSingle, singleMatchData, groupMatchData]);
const handleCardClick = (matchId: number) => {
const matchType = isSingle ? 'one_to_one' : 'group';
gaEvent('home_profile_view', { match_id: matchId, match_type: matchType });
if (isSingle) {
navigate(`${ROUTES.MATCH_SINGLE(matchId.toString())}?type=sent&mode=single`);
} else {
navigate(`${ROUTES.GROUP_MATES(matchId.toString())}?type=sent&mode=group`);
}
};
const hasGames = gameSchedule && gameSchedule.length > 0;
const handleCreateClick = () => {
const matchType = isSingle ? 'one_to_one' : 'group';
gaEvent('match_create_click', { match_type: matchType, role: 'creator' });
onOpenGameInfoBottomSheet();
};
return (
<section className="p-[1.6rem]">
<ButtonCreate
label="맞춤 매칭 생성하기"
className="ml-auto"
textColor={!gameLoading && !hasGames ? 'text-gray-500' : undefined}
onClick={!gameLoading && !hasGames ? undefined : handleCreateClick}
/>
{!gameLoading && !hasGames ? (
<EmptyView
iconName="graphic_empty_2"
className="mt-[4rem]"
text="해당 날짜에는 진행되는 경기가 없어요!"
subText="경기가 있는 다른 날짜를 탐색해 보세요."
/>
) : filteredMatches.length === 0 ? (
<EmptyView
iconName="empty"
className="mt-[4rem]"
text="해당 날짜에 등록된 매칭이 없어요!"
subText="맞춤 매칭을 생성하거나, 다른 날짜를 탐색해 보세요."
/>
) : (
<div className="mt-[1.6rem] space-y-[0.8rem]">
{renderMatchCards(filteredMatches, isSingle, handleCardClick)}
</div>
)}
</section>
);
};
export default MatchListSection;