fix share bug & css
This commit is contained in:
parent
0ab57ddd65
commit
6fad706552
2 changed files with 21 additions and 26 deletions
|
@ -279,6 +279,7 @@ a:active {
|
||||||
.pick-puzzle-type {
|
.pick-puzzle-type {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
column-gap: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-right {
|
.top-right {
|
||||||
|
|
|
@ -70,6 +70,7 @@ export function Game(props: GameProps) {
|
||||||
Try to guarantee a win in <strong>2 guesses</strong>!
|
Try to guarantee a win in <strong>2 guesses</strong>!
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
|
const [shareMsg, setShareMsg] = useState("");
|
||||||
const tableRef = useRef<HTMLTableElement>(null);
|
const tableRef = useRef<HTMLTableElement>(null);
|
||||||
const game = useMemo(
|
const game = useMemo(
|
||||||
() => wasm.Game.new(COMMON_WORDS, puzzle.history),
|
() => wasm.Game.new(COMMON_WORDS, puzzle.history),
|
||||||
|
@ -111,6 +112,24 @@ export function Game(props: GameProps) {
|
||||||
puzzle in {selectedPuzzle.tries} tries! Great job.
|
puzzle in {selectedPuzzle.tries} tries! Great job.
|
||||||
</>);
|
</>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emoji = props.colorBlind
|
||||||
|
? ["⬛", "🟦", "🟧"]
|
||||||
|
: ["⬛", "🟨", "🟩"];
|
||||||
|
const score = (todayStats[puzzleType].tries === 1
|
||||||
|
? "my first try!"
|
||||||
|
: `try #${todayStats[puzzleType].tries}!`
|
||||||
|
);
|
||||||
|
setShareMsg(
|
||||||
|
`I solved ${gameName} #${puzzle.seed} (${puzzleType}🟩) on ${score}\n` +
|
||||||
|
(selectedPuzzle.guesses || [])
|
||||||
|
.map((result) =>
|
||||||
|
clue(result)
|
||||||
|
.map((c) => emoji[c.clue ?? 0])
|
||||||
|
.join("")
|
||||||
|
)
|
||||||
|
.join("\n")
|
||||||
|
);
|
||||||
} else if ((selectedPuzzle.guesses?.length || 0) >= 2) {
|
} else if ((selectedPuzzle.guesses?.length || 0) >= 2) {
|
||||||
setGameState(GameState.Lost);
|
setGameState(GameState.Lost);
|
||||||
setHint(<p>Not quite! The answer could've been <strong>{game.possible_word().toUpperCase()}</strong>. (Enter to try again)</p>);
|
setHint(<p>Not quite! The answer could've been <strong>{game.possible_word().toUpperCase()}</strong>. (Enter to try again)</p>);
|
||||||
|
@ -154,7 +173,6 @@ export function Game(props: GameProps) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("navigator.clipboard.writeText failed:", e);
|
console.warn("navigator.clipboard.writeText failed:", e);
|
||||||
}
|
}
|
||||||
setHint(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const onKey = (key: string) => {
|
const onKey = (key: string) => {
|
||||||
|
@ -219,10 +237,6 @@ export function Game(props: GameProps) {
|
||||||
[puzzleType]: {
|
[puzzleType]: {
|
||||||
...oldStats[puzzleType],
|
...oldStats[puzzleType],
|
||||||
won: true,
|
won: true,
|
||||||
guesses: [
|
|
||||||
...(oldStats[puzzleType].guesses || []),
|
|
||||||
result,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
} else if (guesses.length + 1 === puzzle.history.length + MAX_GUESSES) {
|
} else if (guesses.length + 1 === puzzle.history.length + MAX_GUESSES) {
|
||||||
|
@ -319,27 +333,7 @@ export function Game(props: GameProps) {
|
||||||
{gameState === GameState.Won && (
|
{gameState === GameState.Won && (
|
||||||
<div class="win-buttons">
|
<div class="win-buttons">
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => share("Result copied to clipboard!", shareMsg)}
|
||||||
const emoji = props.colorBlind
|
|
||||||
? ["⬛", "🟦", "🟧"]
|
|
||||||
: ["⬛", "🟨", "🟩"];
|
|
||||||
const score = (todayStats[puzzleType].tries === 1
|
|
||||||
? "my first try!"
|
|
||||||
: `try #${todayStats[puzzleType].tries}!`
|
|
||||||
);
|
|
||||||
share(
|
|
||||||
"Result copied to clipboard!",
|
|
||||||
`I solved ${gameName} #${puzzle.seed} (${puzzleType}🟩) on ${score}\n` +
|
|
||||||
guesses
|
|
||||||
.slice(puzzle.history.length)
|
|
||||||
.map((result) =>
|
|
||||||
clue(result)
|
|
||||||
.map((c) => emoji[c.clue ?? 0])
|
|
||||||
.join("")
|
|
||||||
)
|
|
||||||
.join("\n")
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Share results
|
Share results
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue