"Copy result as emoji" button
This commit is contained in:
parent
c56b7ab526
commit
c7b8a745ed
55
src/Game.tsx
55
src/Game.tsx
|
@ -98,6 +98,21 @@ function Game(props: GameProps) {
|
||||||
setGameNumber((x) => x + 1);
|
setGameNumber((x) => x + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function copyToClipboard(text: string, successHint: string) {
|
||||||
|
if (!navigator.clipboard) {
|
||||||
|
setHint(text);
|
||||||
|
} else {
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(text)
|
||||||
|
.then(() => {
|
||||||
|
setHint(successHint);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setHint(text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onKey = (key: string) => {
|
const onKey = (key: string) => {
|
||||||
if (gameState !== GameState.Playing) {
|
if (gameState !== GameState.Playing) {
|
||||||
if (key === "Enter") {
|
if (key === "Enter") {
|
||||||
|
@ -250,7 +265,10 @@ function Game(props: GameProps) {
|
||||||
</table>
|
</table>
|
||||||
<p
|
<p
|
||||||
role="alert"
|
role="alert"
|
||||||
style={{ userSelect: /https?:/.test(hint) ? "text" : "none" }}
|
style={{
|
||||||
|
userSelect: /https?:/.test(hint) ? "text" : "none",
|
||||||
|
whiteSpace: "pre",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{hint || `\u00a0`}
|
{hint || `\u00a0`}
|
||||||
</p>
|
</p>
|
||||||
|
@ -259,23 +277,32 @@ function Game(props: GameProps) {
|
||||||
<p>
|
<p>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const url = getChallengeUrl(target);
|
copyToClipboard(
|
||||||
if (!navigator.clipboard) {
|
getChallengeUrl(target),
|
||||||
setHint(url);
|
"Challenge link copied to clipboard!"
|
||||||
} else {
|
);
|
||||||
navigator.clipboard
|
|
||||||
.writeText(url)
|
|
||||||
.then(() => {
|
|
||||||
setHint("Challenge link copied to clipboard!");
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setHint(url);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Challenge a friend to this word
|
Challenge a friend to this word
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
copyToClipboard(
|
||||||
|
getChallengeUrl(target) +
|
||||||
|
"\n\n" +
|
||||||
|
guesses
|
||||||
|
.map((guess) =>
|
||||||
|
clue(guess, target)
|
||||||
|
.map((c) => ["⬛", "🟨", "🟩"][c.clue ?? 0])
|
||||||
|
.join("")
|
||||||
|
)
|
||||||
|
.join("\n"),
|
||||||
|
"Result copied to clipboard!"
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Copy result as emoji
|
||||||
|
</button>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{challenge ? (
|
{challenge ? (
|
||||||
|
|
Loading…
Reference in a new issue