Skip to content

Commit 23ac58f

Browse files
committed
handle tweet
1 parent 778c726 commit 23ac58f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

components/your-score.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ export function YourScore({ score, originalGuess, userPrompt, reset }: Props) {
3030
setScoreColorClass(newScoreColorClass);
3131
}, [score]);
3232

33+
const handleShareOnTwitter = () => {
34+
const gameUrl = window.location.href;
35+
const tweetText = `I scored ${similarityScore}% on the "Guess the Prompt" game! Can you beat my score? #GuessThePrompt\n\nPlay the game: ${gameUrl}`;
36+
const tweetUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
37+
tweetText
38+
)}`;
39+
window.open(tweetUrl, "_blank");
40+
};
41+
3342
return (
3443
<div className="p-8">
3544
<h1 className="text-3xl font-bold text-center mb-3">Guess the prompt</h1>
@@ -84,7 +93,10 @@ export function YourScore({ score, originalGuess, userPrompt, reset }: Props) {
8493
{similarityScore}%
8594
</p>
8695
<div className="flex gap-4">
87-
<Button className="bg-blue-500 text-white px-6 py-2 rounded-md">
96+
<Button
97+
className="bg-blue-500 text-white px-6 py-2 rounded-md"
98+
onClick={handleShareOnTwitter}
99+
>
88100
Share on Twitter
89101
</Button>
90102
<Button className="bg-gray-300 px-6 py-2 rounded-md" onClick={reset}>

0 commit comments

Comments
 (0)