-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.tsx
More file actions
289 lines (264 loc) · 8.14 KB
/
Copy pathindex.tsx
File metadata and controls
289 lines (264 loc) · 8.14 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';
import { Button } from '@sopt-makers/ui';
import { m } from 'framer-motion';
import { useRouter } from 'next/router';
import Text from '@/components/common/Text';
import { LoggingImpression } from '@/components/eventLogger/components/LoggingImpression';
import useEventLogger from '@/components/eventLogger/hooks/useEventLogger';
import { useVisibleBadges } from '@/components/members/main/hooks/useVisibleBadges';
import MemberProfileImage from '@/components/members/main/MemberCard/MemberProfileImage';
import { LATEST_GENERATION } from '@/constants/generation';
import { MOBILE_MEDIA_QUERY } from '@/styles/mediaQuery';
// TODO: API 연동 후 optional 제거
interface TeamLeaderCardProps {
id: number;
name: string;
university: string | null;
profileImageUrl: string;
activities: {
id: number;
generation: number;
part: string;
team: string | null;
}[];
introduction: string | null;
teamLeaderElectionDataUrl?: string;
notionIntroductionUrl?: string;
isLoading?: boolean;
selfIntroduction: string;
competitionData: string;
}
const ELLIPSIS_WIDTH = 26;
const BADGE_GAP = 4;
const TeamLeaderCard = ({
id,
name,
university,
profileImageUrl,
activities,
introduction,
selfIntroduction,
competitionData,
}: TeamLeaderCardProps) => {
const router = useRouter();
const { logClickEvent } = useEventLogger();
const sortedGenerationActivities = activities?.sort((a, b) => b.generation - a.generation) || []; // TODO: || [] 테스트 후 삭제
const badges = sortedGenerationActivities.map((activity) => ({
content: `${activity.generation}기 ${activity.part}`,
isActive: activity.generation === LATEST_GENERATION,
}));
const { visibleBadges, isBadgeOverflow, badgeRefs, badgeWrapperRef } = useVisibleBadges(
badges,
ELLIPSIS_WIDTH,
BADGE_GAP,
);
function useDetectWebView() {
const userAgent = navigator.userAgent;
// SOPT-iOS 웹뷰 감지
const isIOSWebView = /SOPT-iOS/.test(navigator.userAgent);
// SOPT-Android 웹뷰 감지 방법:
// 2. User-Agent에 "wv"가 있으면 웹뷰 (기존 방법)
// 3. User-Agent가 정확히 "Chrome/56.0.0.0 Mobile"이면 앱에서 설정한 값이므로 웹뷰
const hasWvInUserAgent = /wv/.test(userAgent);
const isChrome56Mobile = /Chrome\/56\.0\.0\.0 Mobile/.test(userAgent);
const isAndroidWebView = hasWvInUserAgent || isChrome56Mobile;
return {
isWebView: isIOSWebView || isAndroidWebView,
isIOSWebView,
isAndroidWebView,
};
}
const openNotionUrl = (url: string) => {
const notionDeepLinkUrl = url.replace('https://', 'notion://');
const originalUrl = url;
const webViewInfo = useDetectWebView();
//TODO: 웹뷰 환경일 때 Deep Link 처리 앱팀 쪽 협력 요청필요
if (webViewInfo.isWebView) {
window.location.href = originalUrl;
return;
}
// 일반 브라우저에서 노션 앱 열기 시도
try {
// 숨겨진 링크로 노션 앱 열기 시도
const link = document.createElement('a');
link.href = notionDeepLinkUrl;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// 일정 시간 후에도 페이지가 포커스를 잃지 않았다면 앱이 열리지 않은 것으로 간주하고 원래 URL로 fallback
setTimeout(() => {
if (document.hasFocus()) {
window.open(originalUrl, '_blank');
}
}, 1000);
} catch (error) {
// 에러 발생 시 원래 URL로 fallback
window.open(originalUrl, '_blank');
}
};
const handleClickIntroduce = () => {
logClickEvent('TL_introduce');
// TODO: API 연동 후 자기 소개 페이지 이동 로직 추가
openNotionUrl(selfIntroduction);
};
const handleClickAppjamData = () => {
logClickEvent('TL_appjam');
// TODO: API 연동 후 경선 자료 페이지 이동 로직 추가
openNotionUrl(competitionData);
};
const handleClickCard = () => {
logClickEvent('memberCard', { id, name, screen: 'TL' });
router.push(`/members/${id}`);
};
return (
<LoggingImpression eventKey='memberCard' param={{ id, name, screen: 'TL' }}>
<MotionMemberCard whileHover='hover' onClick={handleClickCard}>
<ContentWrapper>
<ImageWrapper>
<MemberProfileImage isLoading={false} imageUrl={profileImageUrl} size='sm' />
</ImageWrapper>
<ContentArea>
<TitleBox>
<Text typography='SUIT_18_SB'>{name}</Text>
<Text typography='SUIT_12_SB' color={colors.gray200}>
{university}
</Text>
</TitleBox>
<BadgesBox ref={badgeWrapperRef}>
<Badges>
{visibleBadges?.map((badge, idx) => (
<Badge
ref={(el: HTMLDivElement) => (badgeRefs.current[idx] = el)}
key={idx}
isActive={badge.isActive}
>
{badge.isActive && <BadgeActiveDot />}
<Text typography='SUIT_11_SB' color={badge.isActive ? colors.secondary : colors.gray200}>
{badge.content}
</Text>
</Badge>
))}
{isBadgeOverflow && (
<Badge isActive={false}>
<Text typography='SUIT_11_SB'>...</Text>
</Badge>
)}
</Badges>
</BadgesBox>
<Intro typography='SUIT_13_M' color={colors.gray200}>
{introduction}
</Intro>
</ContentArea>
</ContentWrapper>
<ButtonWrapper onClick={(e) => e.stopPropagation()}>
<Button variant='fill' theme='black' style={{ width: '100%' }} onClick={handleClickIntroduce}>
자기 소개 보기
</Button>
<Button variant='fill' theme='white' style={{ width: '100%' }} onClick={handleClickAppjamData}>
경선 자료 보기
</Button>
</ButtonWrapper>
</MotionMemberCard>
</LoggingImpression>
);
};
const ContentWrapper = styled.div`
display: flex;
flex-direction: row;
gap: 16px;
width: 100%;
`;
const ButtonWrapper = styled.div`
display: flex;
gap: 8px;
width: 100%;
`;
const Intro = styled(Text)`
display: ${'-webkit-box'};
margin-top: 8px;
width: 100%;
overflow: hidden;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
@media ${MOBILE_MEDIA_QUERY} {
margin-top: 8px;
font-size: 13px;
font-weight: 600;
-webkit-line-clamp: 1;
}
`;
const BadgeActiveDot = styled.span`
border-radius: 50%;
background-color: ${colors.secondary};
width: 6px;
height: 6px;
`;
const Badge = styled.div<{ isActive: boolean }>`
display: flex;
flex-direction: row;
flex-shrink: 0;
gap: 6px;
align-items: center;
border-radius: 6px;
background-color: ${({ isActive }) => (isActive ? 'rgb(247 114 52 / 20%)' : colors.gray700)};
padding: 6px;
height: 22px;
line-height: 0;
@media ${MOBILE_MEDIA_QUERY} {
padding: 4px 6px;
color: ${colors.gray100};
}
`;
const Badges = styled.div`
display: flex;
gap: ${BADGE_GAP}px;
width: fit-content;
height: 22px;
`;
const BadgesBox = styled.div`
position: relative;
margin-top: 8px;
overflow-x: hidden;
`;
const ImageWrapper = styled.div`
display: flex;
align-items: center;
justify-content: center;
width: 80px;
height: 80px;
`;
const TitleBox = styled.div`
display: flex;
gap: 4px;
align-items: center;
`;
const ContentArea = styled.div`
display: flex;
flex-direction: column;
width: 100%;
overflow: hidden;
@media ${MOBILE_MEDIA_QUERY} {
min-height: unset;
}
`;
const MotionMemberCard = styled(m.div)`
display: flex;
position: relative;
flex-direction: column;
gap: 20px;
align-items: center;
transition: box-shadow 0.3s;
border-radius: 16px;
background-color: ${colors.gray900};
cursor: pointer;
padding: 16px 20px;
width: 316px;
@media ${MOBILE_MEDIA_QUERY} {
position: relative;
border-radius: 10px;
width: 100%;
}
`;
export default TeamLeaderCard;