Skip to content

Commit 2629633

Browse files
authored
[TASK-211 / 25.07.01] Feature - 리더보드 username 대응 개발 (#44)
1 parent 3fbd69b commit 2629633

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

src/app/(auth-required)/leaderboards/Content.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { startHolyLoader } from 'holy-loader';
55
import { useMemo } from 'react';
66
import { leaderboardList } from '@/apis';
77
import { Rank } from '@/app/components';
8-
import { PATHS } from '@/constants';
8+
import { PATHS, URLS } from '@/constants';
99
import { useSearchParam } from '@/hooks';
1010
import { Dropdown } from '@/shared';
1111
import { LeaderboardItemType } from '@/types';
@@ -26,13 +26,17 @@ export const Content = () => {
2626
});
2727

2828
const data = useMemo(() => {
29-
const value = (
30-
searchParams.based === 'user' ? boards?.users : boards?.posts
31-
) as LeaderboardItemType[];
29+
const isUserBased = searchParams.based === 'user';
30+
const isViewBased = searchParams.sort === 'viewCount';
31+
32+
const value = (isUserBased ? boards?.users : boards?.posts) as LeaderboardItemType[];
33+
3234
return (
33-
value.map((item) => ({
34-
name: searchParams.based === 'user' ? item.email.split('@')[0] : item.title,
35-
value: searchParams.sort === 'viewCount' ? item.viewDiff : item.likeDiff,
35+
value.map(({ username, title, viewDiff, likeDiff, slug }) => ({
36+
key: isUserBased ? username : title,
37+
username,
38+
url: URLS.VELOG + `/@${username}` + (isUserBased ? '/posts' : `/${slug}`),
39+
value: isViewBased ? viewDiff : likeDiff,
3640
})) || []
3741
);
3842
}, [boards, searchParams.based, searchParams.sort]);
@@ -86,8 +90,15 @@ export const Content = () => {
8690
</div>
8791

8892
<div className="w-full flex flex-wrap gap-5 overflow-auto">
89-
{data?.map(({ name, value }, index) => (
90-
<Rank name={name} key={index} count={value} rank={index + 1} />
93+
{data?.map(({ key, username, url, value }, index) => (
94+
<Rank
95+
name={key}
96+
key={index}
97+
url={url}
98+
count={value}
99+
rank={index + 1}
100+
suffix={searchParams.based === 'post' ? username : ''}
101+
/>
91102
))}
92103
</div>
93104
</div>

src/app/components/Rank.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
1+
'use client';
2+
13
import { HTMLAttributes } from 'react';
24
import { twMerge } from 'tailwind-merge';
35

46
export interface IProp extends HTMLAttributes<HTMLDivElement> {
57
name: string;
68
rank: number;
9+
url: string;
710
count?: string | number;
811
suffix?: string;
912
}
1013

1114
const colorTable = ['border-[#DAA520]', 'border-[#A9A9A9]', 'border-[#B87333]'];
1215

13-
export const Rank = ({ name, rank, count, suffix = '회' }: IProp) => {
16+
export const Rank = ({ name, rank, count, url, suffix }: IProp) => {
1417
return (
15-
<div
18+
<button
1619
className={twMerge(
17-
'min-w-[40%] w-full p-[25px] bg-BG-SUB rounded-[4px] gap-3 justify-between flex',
20+
'min-w-[40%] group w-full p-[25px] bg-BG-SUB rounded-[4px] gap-3 justify-between flex cursor-pointer items-center',
1821
rank > 3 ? 'border-0' : `border-2 ${colorTable[rank - 1]}`,
1922
)}
23+
onClick={() => window.open(url, '_blank', 'noopener,noreferrer')}
2024
>
21-
<span
22-
data-rank={rank}
23-
className="text-TITLE-3 text-TEXT-MAIN flex items-center gap-3 before:content-[attr(data-rank)_'위'] before:text-SUBTITLE-4 before:text-TEXT-ALT max-TBL:text-TITLE-4 max-TBL:before:text-SUBTITLE-5 max-MBI:text-SUBTITLE-4 max-MBI:before:text-SUBTITLE-5"
24-
>
25-
{name}
26-
</span>
25+
<div className="flex items-center gap-3">
26+
<span className="text-SUBTITLE-4 text-TEXT-ALT shrink-0 max-TBL:text-SUBTITLE-5 max-MBI:text-SUBTITLE-5">
27+
{rank + '위'}
28+
</span>
29+
30+
<div className=" flex flex-col gap-0">
31+
<span className="group-hover:underline text-TITLE-3 text-TEXT-MAIN flex items-center gap-3 max-TBL:text-TITLE-4 max-MBI:text-SUBTITLE-4">
32+
{name}
33+
</span>
34+
{suffix !== undefined && (
35+
<span className="text-SUBTITLE-4 text-TEXT-ALT max-TBL:text-SUBTITLE-5 max-MBI:text-SUBTITLE-5">
36+
{String(suffix)}
37+
</span>
38+
)}
39+
</div>
40+
</div>
41+
2742
<span className="text-SUBTITLE-3 shrink-0 text-TEXT-SUB max-TBL:text-TITLE-4 max-MBI:text-SUBTITLE-4">
28-
{count}
29-
{suffix}
43+
{count}
3044
</span>
31-
</div>
45+
</button>
3246
);
3347
};

src/types/leaderboard.type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type LeaderboardListUser = {
22
id: string;
33
email: string;
4+
username: string;
45
totalViews: string;
56
totalLikes: string;
67
totalPosts: string;
@@ -12,6 +13,7 @@ type LeaderboardListPost = {
1213
id: string;
1314
title: string;
1415
slug: string;
16+
username: string;
1517
totalViews: number;
1618
totalLikes: number;
1719
viewDiff: number;

0 commit comments

Comments
 (0)