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 fd52009
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ function Game(props: GameProps) {
setGameNumber((x) => x + 1);
};

async function share(copiedHint: string, text?: string) {
const url = seed
async function share(
copiedHint: string,
text?: string,
customTarget?: string
) {
const url = customTarget
? getChallengeUrl(customTarget)
: seed
? window.location.origin + window.location.pathname + currentSeedParams()
: getChallengeUrl(target);
const body = url + (text ? "\n\n" + text : "");
Expand Down Expand Up @@ -355,6 +361,29 @@ 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 if (currentGuess.length > 0) {
setHint("Too short");
} else {
setHint("Please make a guess first");
}
}}
>
Create a custom game from current guess
</button>
</p>
</div>
);
}
Expand Down

0 comments on commit fd52009

Please sign in to comment.