Skip to content

Commit 98d9790

Browse files
authored
Merge pull request #339 from boostcampwm-2022/refactor/frontend-ranking
Refactor: 랭킹페이지, 랭킹 컴포넌트
2 parents 83ea2c4 + 327d227 commit 98d9790

File tree

4 files changed

+66
-51
lines changed

4 files changed

+66
-51
lines changed

frontend/src/components/Ranking/RankingTable/index.tsx

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Children } from 'react';
2-
import styled from 'styled-components';
2+
import styled, { css } from 'styled-components';
33

44
type TextAlignType = 'center' | 'right' | 'left';
55

@@ -32,6 +32,10 @@ interface StyledContainer {
3232
tdAlignList: TextAlignType[];
3333
}
3434

35+
interface StyledRow {
36+
isHover: boolean;
37+
}
38+
3539
/**
3640
* Head 컴포넌트는 Ranking 컴포넌트의 자식 컴포넌트로 사용되어야 하고 Row 컴포넌트보다 먼저 사용되어야 합니다.
3741
*/
@@ -47,7 +51,12 @@ function Head({ children }: HeadProps) {
4751
* Row 컴포넌트는 Ranking 컴포넌트의 자식 컴포넌트로 사용되어야 합니다.
4852
*/
4953
function Row({ children, onClick }: RowProps) {
50-
return <tr onClick={onClick}>{children}</tr>;
54+
const isHover = !!onClick;
55+
return (
56+
<Tr onClick={onClick} isHover={isHover}>
57+
{children}
58+
</Tr>
59+
);
5160
}
5261

5362
/**
@@ -118,33 +127,34 @@ const Container = styled.table<StyledContainer>`
118127
}
119128
}
120129
}
130+
`;
121131

122-
tbody {
123-
tr {
124-
padding: 0 15px;
125-
background-color: ${(props) => props.theme.colors.black3};
126-
transition: background-color 0.1s ease-in-out;
127-
cursor: pointer;
128-
td {
129-
vertical-align: middle;
130-
height: 76px;
131-
font-size: ${(props) => props.theme.fontSize.lg};
132-
133-
&:first-of-type {
134-
border-top-left-radius: 8px;
135-
border-bottom-left-radius: 8px;
136-
}
137-
138-
&:last-of-type {
139-
border-top-right-radius: 8px;
140-
border-bottom-right-radius: 8px;
141-
padding-right: 20px;
142-
}
143-
}
132+
const Tr = styled.tr<StyledRow>`
133+
padding: 0 15px;
134+
background-color: ${(props) => props.theme.colors.black3};
135+
transition: background-color 0.1s ease-in-out;
136+
td {
137+
vertical-align: middle;
138+
height: 76px;
139+
font-size: ${(props) => props.theme.fontSize.lg};
140+
141+
&:first-of-type {
142+
border-top-left-radius: 8px;
143+
border-bottom-left-radius: 8px;
144+
}
144145
146+
&:last-of-type {
147+
border-top-right-radius: 8px;
148+
border-bottom-right-radius: 8px;
149+
padding-right: 20px;
150+
}
151+
}
152+
${(props) =>
153+
props.isHover &&
154+
css`
155+
cursor: pointer;
145156
&:hover {
146157
background-color: ${(props) => props.theme.colors.gray1};
147158
}
148-
}
149-
}
159+
`}
150160
`;

frontend/src/pages/ranking.tsx

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,33 @@ function Ranking({ tier, username, page }: RankingProps) {
7070
<RankingTable.Element>{t('common:table-score')}</RankingTable.Element>
7171
<RankingTable.Element>{t('common:table-tech-stack')}</RankingTable.Element>
7272
</RankingTable.Head>
73-
{data?.users.map(({ id, username, avatarUrl, tier, score, primaryLanguages }, index) => (
74-
<RankingTable.Row key={id} onClick={() => searchUser(username)}>
75-
<RankingTable.Element>
76-
<GrayText>{(page - 1) * COUNT_PER_PAGE + index + 1}</GrayText>
77-
</RankingTable.Element>
78-
<RankingTable.Element>
79-
<Avatar src={avatarUrl} name={username} />
80-
</RankingTable.Element>
81-
<RankingTable.Element>
82-
<CubeIcon tier={tier} />
83-
</RankingTable.Element>
84-
<RankingTable.Element>
85-
<GrayText>{score?.toLocaleString()}</GrayText>
86-
</RankingTable.Element>
87-
<RankingTable.Element>
88-
<TechStackList>
89-
{primaryLanguages.map((lang) => (
90-
<li key={lang}>
91-
<LanguageIcon language={lang} width={35} height={35} />
92-
</li>
93-
))}
94-
</TechStackList>
95-
</RankingTable.Element>
96-
</RankingTable.Row>
97-
))}
73+
{data?.users.map(
74+
({ id, username, avatarUrl, tier: eachTier, score, primaryLanguages, totalRank, tierRank }) => (
75+
<RankingTable.Row key={id} onClick={() => searchUser(username)}>
76+
<RankingTable.Element>
77+
<GrayText>{tier === 'all' ? totalRank : tierRank}</GrayText>
78+
</RankingTable.Element>
79+
<RankingTable.Element>
80+
<Avatar src={avatarUrl} name={username} />
81+
</RankingTable.Element>
82+
<RankingTable.Element>
83+
<CubeIcon tier={eachTier} />
84+
</RankingTable.Element>
85+
<RankingTable.Element>
86+
<GrayText>{score?.toLocaleString()}</GrayText>
87+
</RankingTable.Element>
88+
<RankingTable.Element>
89+
<TechStackList>
90+
{primaryLanguages.map((lang) => (
91+
<li key={lang}>
92+
<LanguageIcon language={lang} width={35} height={35} />
93+
</li>
94+
))}
95+
</TechStackList>
96+
</RankingTable.Element>
97+
</RankingTable.Row>
98+
),
99+
)}
98100
</RankingTable>
99101
{isLoading && Array.from({ length: COUNT_PER_PAGE }).map((_, index) => <RankingSkeleton key={index} />)}
100102
{isError && <NotFound />}

frontend/src/type/response.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface RankingResponse {
2020
avatarUrl: string;
2121
dailyViews: number;
2222
score: number;
23+
totalRank: number;
24+
tierRank: number;
2325
scoreDifference: number;
2426
primaryLanguages: string[];
2527
}

frontend/src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const LANGUAGE_MAP: {
3737
'objective-c': 'objectivec',
3838
'asp.net': 'asp',
3939
hcl: 'hashicorp',
40+
rust: 'light_rust',
4041
};
4142

4243
export const CUBE_RANK = {

0 commit comments

Comments
 (0)