1
- "use client" ;
2
-
3
- import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
1
+ import { Card } from "@/components/ui/card" ;
4
2
import { Progress } from "@/components/ui/progress" ;
5
- import { useEffect , useState } from "react" ;
6
-
7
- type Rank = {
8
- min : number ;
9
- max : number ;
10
- color : string ;
11
- bgColor : string ;
12
- } ;
3
+ import type { UserRate as Rate } from "@/types" ;
13
4
14
- const ranks : { [ key : string ] : Rank } = {
5
+ const ranks : { [ key : string ] : { color : string ; bgColor : string } } = {
15
6
ブロンズ : {
16
- min : 0 ,
17
- max : 499 ,
18
7
color : "text-orange-500" ,
19
8
bgColor : "bg-orange-100" ,
20
9
} ,
21
10
シルバー : {
22
- min : 500 ,
23
- max : 999 ,
24
11
color : "text-slate-500" ,
25
12
bgColor : "bg-slate-100" ,
26
13
} ,
27
14
ゴールド : {
28
- min : 1000 ,
29
- max : 1499 ,
30
15
color : "text-yellow-500" ,
31
16
bgColor : "bg-yellow-100" ,
32
17
} ,
33
18
プラチナ : {
34
- min : 1500 ,
35
- max : 1999 ,
36
19
color : "text-emerald-500" ,
37
20
bgColor : "bg-emerald-100" ,
38
21
} ,
39
22
ダイヤモンド : {
40
- min : 2000 ,
41
- max : 2499 ,
42
23
color : "text-blue-500" ,
43
24
bgColor : "bg-blue-100" ,
44
25
} ,
45
26
マスター : {
46
- min : 2500 ,
47
- max : 2999 ,
48
27
color : "text-purple-500" ,
49
28
bgColor : "bg-purple-100" ,
50
29
} ,
51
30
プレデター : {
52
- min : 3000 ,
53
- max : 3499 ,
54
31
color : "text-red-500" ,
55
32
bgColor : "bg-red-100" ,
56
33
} ,
57
34
} ;
58
35
59
- const getCurrentRank = ( rating : number ) : string | undefined => {
60
- return Object . entries ( ranks ) . find (
61
- ( [ _ , { min, max } ] ) => rating >= min && rating <= max ,
62
- ) ?. [ 0 ] ;
36
+ type RateProps = {
37
+ rate : Rate ;
63
38
} ;
64
39
65
- interface PlayerRankCardProps {
66
- rankPoint : number ;
67
- }
68
-
69
- export default function PlayerRankCard ( { rankPoint } : PlayerRankCardProps ) {
70
- const [ currentRank , setCurrentRank ] = useState < string | undefined > (
71
- getCurrentRank ( rankPoint ) ,
72
- ) ;
73
-
74
- useEffect ( ( ) => {
75
- setCurrentRank ( getCurrentRank ( rankPoint ) ) ;
76
- } , [ rankPoint ] ) ;
77
-
78
- const nextRank =
79
- currentRank &&
80
- ( Object . keys ( ranks ) [ Object . keys ( ranks ) . indexOf ( currentRank ) + 1 ] ||
81
- undefined ) ;
82
-
83
- if ( ! currentRank ) {
40
+ export default function PlayerRankCard ( { rate } : RateProps ) {
41
+ if ( ! rate . rate ) {
84
42
return (
85
43
< div className = "w-[21rem]" >
86
44
< Card className = "w-full max-w-md space-y-6 p-8" >
@@ -90,11 +48,17 @@ export default function PlayerRankCard({ rankPoint }: PlayerRankCardProps) {
90
48
) ;
91
49
}
92
50
51
+ // 現在のランクに対応するスタイルを取得
52
+ const rankStyles = ranks [ rate . rate . name ] || {
53
+ color : "text-gray-500" ,
54
+ bgColor : "bg-gray-100" ,
55
+ } ;
56
+
93
57
const rankPositionPercentage =
94
58
100 -
95
59
Math . floor (
96
- ( ( rankPoint - ranks [ currentRank ] . min ) /
97
- ( ranks [ currentRank ] . max - ranks [ currentRank ] . min ) ) *
60
+ ( ( rate . ratePoint - rate . rate . minRange ) /
61
+ ( rate . rate . maxRange - rate . rate . minRange ) ) *
98
62
100 ,
99
63
) ;
100
64
@@ -103,23 +67,23 @@ export default function PlayerRankCard({ rankPoint }: PlayerRankCardProps) {
103
67
< Card className = "w-full max-w-md space-y-6 p-8" >
104
68
< div className = "flex justify-between items-center" >
105
69
< div >
106
- < h3 className = { `text-3xl font-bold ${ ranks [ currentRank ] . color } ` } >
107
- { currentRank }
70
+ < h3 className = { `text-3xl font-bold ${ rankStyles . color } ` } >
71
+ { rate . rate . name }
108
72
</ h3 >
109
73
< p className = "text-sm text-muted-foreground" > 現在のランク</ p >
110
74
</ div >
111
75
< div
112
- className = { `w-16 h-16 rounded-full ${ ranks [ currentRank ] . bgColor } flex items-center justify-center` }
76
+ className = { `w-16 h-16 rounded-full flex items-center justify-center ${ rankStyles . bgColor } ` }
113
77
>
114
- < span className = { `text-2xl font-bold ${ ranks [ currentRank ] . color } ` } >
115
- { rankPoint }
78
+ < span className = { `text-2xl font-bold ${ rankStyles . color } ` } >
79
+ { rate . ratePoint }
116
80
</ span >
117
81
</ div >
118
82
</ div >
119
83
< Progress
120
84
value = {
121
- ( ( rankPoint - ranks [ currentRank ] . min ) /
122
- ( ranks [ currentRank ] . max - ranks [ currentRank ] . min ) ) *
85
+ ( ( rate . ratePoint - rate . rate . minRange ) /
86
+ ( rate . rate . maxRange - rate . rate . minRange ) ) *
123
87
100
124
88
}
125
89
className = "h-2 bg-gray-200"
@@ -129,33 +93,33 @@ export default function PlayerRankCard({ rankPoint }: PlayerRankCardProps) {
129
93
< div >
130
94
< p className = "text-muted-foreground" > ランク範囲</ p >
131
95
< p className = "font-semibold" >
132
- { ranks [ currentRank ] . min } - { ranks [ currentRank ] . max } LP
96
+ { rate . rate . minRange } - { rate . rate . maxRange } LP
133
97
</ p >
134
98
</ div >
135
- { nextRank && (
99
+ { rate . nextRate && (
136
100
< >
137
101
< div >
138
102
< p className = "text-muted-foreground" > 次のランク</ p >
139
- < p className = "font-semibold" > { nextRank } </ p >
103
+ < p className = "font-semibold" > { rate . nextRate . name } </ p >
140
104
</ div >
141
105
< div >
142
106
< p className = "text-muted-foreground" > 次のランクまで</ p >
143
107
< p className = "font-semibold" >
144
- { ranks [ currentRank ] . max - rankPoint } LP
108
+ { rate . rate . maxRange - rate . ratePoint + 1 } LP
145
109
</ p >
146
110
</ div >
147
111
</ >
148
112
) }
149
113
< div >
150
114
< p className = "text-muted-foreground" > 現在のLP</ p >
151
- < p className = "font-semibold" > { rankPoint } LP</ p >
115
+ < p className = "font-semibold" > { rate . ratePoint } LP</ p >
152
116
</ div >
153
117
</ div >
154
- < div className = { `p-4 rounded-lg ${ ranks [ currentRank ] . bgColor } ` } >
118
+ < div className = { `p-4 rounded-lg ${ rankStyles . bgColor } ` } >
155
119
< p className = "text-center text-sm mb-1" > ランク内での位置</ p >
156
120
< div className = "flex gap-2 justify-center items-center" >
157
121
< p className = "text-sm font-bold" > 上位</ p >
158
- < p className = " text-center text-2xl font-bold" >
122
+ < p className = { ` text-center text-2xl font-bold ${ rankStyles . color } ` } >
159
123
{ rankPositionPercentage } %
160
124
</ p >
161
125
</ div >
0 commit comments