Skip to content

Commit 1eed42b

Browse files
author
Ananta
committed
fix: copy full comparison result data as JSON
1 parent d682cef commit 1eed42b

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

components/result-dashboard.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function ResultDashboard({ user1, user2 }: Props) {
3030
const loser = winner === user1 ? user2 : user1;
3131
const diffPct = winner
3232
? Math.round(
33-
((winner.finalScore - loser.finalScore) / loser.finalScore) * 100,
34-
)
33+
((winner.finalScore - loser.finalScore) / loser.finalScore) * 100,
34+
)
3535
: 0;
3636
const repoDiff =
3737
Math.max(user1.repoScore, user2.repoScore) -
@@ -99,28 +99,28 @@ export function ResultDashboard({ user1, user2 }: Props) {
9999
};
100100

101101
const handleCopy = async () => {
102-
const summary = {
103-
comparison: {
104-
[user1.username]: {
105-
finalScore: user1.finalScore,
106-
repoScore: user1.repoScore,
107-
prScore: user1.prScore,
108-
contributionScore: user1.contributionScore,
102+
try {
103+
const summary = {
104+
comparison: {
105+
user1,
106+
user2,
107+
winner: winner
108+
? {
109+
username: winner.username,
110+
name: winner.name || winner.username,
111+
finalScore: winner.finalScore,
112+
}
113+
: "tie",
114+
leadBy: winner ? `${diffPct}%` : "0%",
115+
insights: getInsights(),
109116
},
110-
[user2.username]: {
111-
finalScore: user2.finalScore,
112-
repoScore: user2.repoScore,
113-
prScore: user2.prScore,
114-
contributionScore: user2.contributionScore,
115-
},
116-
winner: winner?.username ?? "tie",
117-
leadBy: winner ? `${diffPct}%` : "0%",
118-
insights: getInsights(),
119-
},
120-
};
121-
await navigator.clipboard.writeText(JSON.stringify(summary, null, 2));
122-
setCopied(true);
123-
setTimeout(() => setCopied(false), 2000);
117+
};
118+
await navigator.clipboard.writeText(JSON.stringify(summary, null, 2));
119+
setCopied(true);
120+
setTimeout(() => setCopied(false), 2000);
121+
} catch (error) {
122+
console.error("Copy failed:", error);
123+
}
124124
};
125125

126126
return (

0 commit comments

Comments
 (0)