Skip to content

Commit

Permalink
Add a button to create a custom link from last guess
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshgupta137 committed Feb 1, 2022
1 parent 135c0a8 commit fa4c126
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ function Game(props: GameProps) {
setGameNumber((x) => x + 1);
};

async function share(copiedHint: string, text?: string) {
async function share(
copiedHint: string,
text?: string,
customTarget?: string
) {
const url = seed
? window.location.origin + window.location.pathname + currentSeedParams()
: getChallengeUrl(target);
: getChallengeUrl(customTarget ? customTarget : target);
const body = url + (text ? "\n\n" + text : "");
if (
/android|iphone|ipad|ipod|webos/i.test(navigator.userAgent) &&
Expand Down Expand Up @@ -355,6 +359,27 @@ function Game(props: GameProps) {
</button>
)}
</p>
<p>
<button
onClick={() => {
if (currentGuess.length >= minLength) {
if (dictionary.includes(currentGuess)) {
share(
`Link for word "${currentGuess.toUpperCase()}" copied to clipboard!`,
"I created this challenge for you!",
currentGuess
);
} else {
setHint("Not a valid word");
}
} else {
setHint("Please make a guess first");
}
}}
>
Create a custom game from last guess
</button>
</p>
</div>
);
}
Expand Down

0 comments on commit fa4c126

Please sign in to comment.