Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button to create a custom link from last guess #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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