|
1 | 1 | import { UserResult } from "@/types/user-result"; |
2 | | -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "./ui/card"; |
| 2 | +import { |
| 3 | + Card, |
| 4 | + CardContent, |
| 5 | + CardDescription, |
| 6 | + CardHeader, |
| 7 | + CardTitle, |
| 8 | +} from "./ui/card"; |
3 | 9 | import { Progress } from "./ui/progress"; |
4 | | - |
| 10 | +import { useTranslation } from "./language-provider"; |
5 | 11 |
|
6 | 12 | type Props = { |
7 | 13 | user1: UserResult; |
8 | 14 | user2: UserResult; |
9 | 15 | }; |
10 | 16 |
|
11 | 17 | export function BreakdownBars({ user1, user2 }: Props) { |
12 | | - const getMaxScore = (score1: number, score2: number) => Math.max(score1, score2, 1) |
13 | | - |
| 18 | + const getMaxScore = (score1: number, score2: number) => |
| 19 | + Math.max(score1, score2, 1); |
| 20 | + const { t,dir } = useTranslation(); |
14 | 21 |
|
15 | 22 | return ( |
16 | | - <Card> |
17 | | - <CardHeader> |
18 | | - <CardTitle>Detailed Breakdown</CardTitle> |
19 | | - <CardDescription>Progress bars showing relative performance</CardDescription> |
20 | | - </CardHeader> |
21 | | - <CardContent className="space-y-6"> |
22 | | - {["repoScore", "prScore", "contributionScore"].map((metric) => { |
23 | | - const user1Value = user1[metric as keyof UserResult] as number |
24 | | - const user2Value = user2[metric as keyof UserResult] as number |
25 | | - const maxVal = getMaxScore(user1Value, user2Value) |
26 | | - const metricLabel = metric === "repoScore" ? "Repository Score" : metric === "prScore" ? "Pull Request Score" : "Contribution Score" |
27 | | - return ( |
28 | | - <div key={metric} className="space-y-2 pe-2"> |
29 | | - <div className="flex justify-between text-sm"> |
30 | | - <span>{metricLabel}</span> |
31 | | - <span className="text-muted-foreground"> |
32 | | - {user1.username}: {user1Value} | {user2.username}: {user2Value} |
33 | | - </span> |
34 | | - </div> |
35 | | - <div className="space-y-1 "> |
36 | | - <div className="flex items-center gap-2"> |
37 | | - <span className="text-xs w-24 truncate">{user1.username}</span> |
38 | | - <Progress value={(user1Value / maxVal) * 100} className="flex-1 h-2" /> |
39 | | - <span className="text-xs w-8">{user1Value}</span> |
40 | | - </div> |
41 | | - <div className="flex items-center gap-2"> |
42 | | - <span className="text-xs w-24 truncate">{user2.username}</span> |
43 | | - <Progress value={(user2Value / maxVal) * 100} className="flex-1 h-2" /> |
44 | | - <span className="text-xs w-8">{user2Value}</span> |
45 | | - </div> |
46 | | - </div> |
47 | | - </div> |
48 | | - ) |
49 | | - })} |
50 | | - </CardContent> |
51 | | - </Card> |
| 23 | + <Card> |
| 24 | + <CardHeader> |
| 25 | + <CardTitle>{t('breakdown.title')}</CardTitle> |
| 26 | + <CardDescription> |
| 27 | + {t('breakdown.description')} |
| 28 | + </CardDescription> |
| 29 | + </CardHeader> |
| 30 | + <CardContent className="space-y-6"> |
| 31 | + {["repoScore", "prScore", "contributionScore"].map((metric) => { |
| 32 | + const user1Value = user1[metric as keyof UserResult] as number; |
| 33 | + const user2Value = user2[metric as keyof UserResult] as number; |
| 34 | + const maxVal = getMaxScore(user1Value, user2Value); |
| 35 | + const metricLabel = |
| 36 | + metric === "repoScore" |
| 37 | + ? "breakdown.repo" |
| 38 | + : metric === "prScore" |
| 39 | + ? "breakdown.pr" |
| 40 | + : "breakdown.contribution"; |
| 41 | + return ( |
| 42 | + <div key={metric} className="space-y-2 pe-2"> |
| 43 | + <div className="flex justify-between text-sm"> |
| 44 | + <span>{t(metricLabel)}</span> |
| 45 | + <span className="text-muted-foreground"> |
| 46 | + {user1.username}: {user1Value} | {user2.username}:{" "} |
| 47 | + {user2Value} |
| 48 | + </span> |
| 49 | + </div> |
| 50 | + <div className="space-y-1 "> |
| 51 | + <div className="flex items-center gap-2"> |
| 52 | + <span className="text-xs w-24 truncate"> |
| 53 | + {user1.username} |
| 54 | + </span> |
| 55 | + <Progress |
| 56 | + value={(user1Value / maxVal) * 100} |
| 57 | + className="flex-1 h-2" |
| 58 | + /> |
| 59 | + <span className="text-xs w-8">{user1Value}</span> |
| 60 | + </div> |
| 61 | + <div className="flex items-center gap-2"> |
| 62 | + <span className="text-xs w-24 truncate"> |
| 63 | + {user2.username} |
| 64 | + </span> |
| 65 | + <Progress |
| 66 | + value={(user2Value / maxVal) * 100} |
| 67 | + className="flex-1 h-2" |
| 68 | + /> |
| 69 | + <span className="text-xs w-8">{user2Value}</span> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + ); |
| 74 | + })} |
| 75 | + </CardContent> |
| 76 | + </Card> |
52 | 77 | ); |
53 | 78 | } |
0 commit comments