Skip to content

Commit fe75ce0

Browse files
committed
feat: add Copy Result button with clipboard support
Closes #35
1 parent 60c8f15 commit fe75ce0

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

components/result-dashboard.tsx

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
"use client";
2+
3+
import { useState } from "react";
14
import { ComparisonTable } from "./comparison-table";
25
import { ComparisonChart } from "./comparison-chart";
36
import { BreakdownBars } from "./breakdown-bars";
47
import { TopList } from "./top-list";
58
import { InsightsList } from "./insights-list";
69
import { ScoreCard } from "./score-card";
710
import { Card, CardContent } from "./ui/card";
8-
import { Trophy } from "lucide-react";
11+
import { Trophy, Copy, Check } from "lucide-react";
912
import { UserResult } from "@/types/user-result";
1013

1114
type Props = {
@@ -14,12 +17,39 @@ type Props = {
1417
};
1518

1619
export function ResultDashboard({ user1, user2 }: Props) {
20+
const [copied, setCopied] = useState(false);
21+
1722
const winner =
1823
user1.finalScore === user2.finalScore
1924
? null
2025
: user1.finalScore > user2.finalScore
2126
? user1
2227
: user2;
28+
29+
const handleCopy = async () => {
30+
const summary = {
31+
winner: winner?.username ?? "Tie",
32+
users: [
33+
{
34+
username: user1.username,
35+
finalScore: user1.finalScore,
36+
repoScore: user1.repoScore,
37+
prScore: user1.prScore,
38+
contributionScore: user1.contributionScore,
39+
},
40+
{
41+
username: user2.username,
42+
finalScore: user2.finalScore,
43+
repoScore: user2.repoScore,
44+
prScore: user2.prScore,
45+
contributionScore: user2.contributionScore,
46+
},
47+
],
48+
};
49+
await navigator.clipboard.writeText(JSON.stringify(summary, null, 2));
50+
setCopied(true);
51+
setTimeout(() => setCopied(false), 2000);
52+
};
2353
const loser = winner === user1 ? user2 : user1;
2454
const diffPct = winner
2555
? Math.round(
@@ -128,6 +158,25 @@ export function ResultDashboard({ user1, user2 }: Props) {
128158
<TopList userResults={[user1, user2]} />
129159

130160
<InsightsList insights={getInsights()} />
161+
162+
<div className="flex justify-center">
163+
<button
164+
onClick={handleCopy}
165+
className="inline-flex items-center gap-2 rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground"
166+
>
167+
{copied ? (
168+
<>
169+
<Check className="h-4 w-4 text-green-500" />
170+
Copied!
171+
</>
172+
) : (
173+
<>
174+
<Copy className="h-4 w-4" />
175+
Copy Result
176+
</>
177+
)}
178+
</button>
179+
</div>
131180
</div>
132181
);
133182
}

0 commit comments

Comments
 (0)