From 6fad706552737e6a34d1134e83ab85298f1f062f Mon Sep 17 00:00:00 2001
From: ashastral
Date: Tue, 15 Mar 2022 22:23:07 -0700
Subject: [PATCH] fix share bug & css
---
web-optimle/www/src/App.css | 1 +
web-optimle/www/src/Game.tsx | 46 ++++++++++++++++--------------------
2 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/web-optimle/www/src/App.css b/web-optimle/www/src/App.css
index e281cd1..bc3fb06 100644
--- a/web-optimle/www/src/App.css
+++ b/web-optimle/www/src/App.css
@@ -279,6 +279,7 @@ a:active {
.pick-puzzle-type {
display: flex;
flex-direction: row;
+ column-gap: 0.5em;
}
.top-right {
diff --git a/web-optimle/www/src/Game.tsx b/web-optimle/www/src/Game.tsx
index b5be67d..5fb1143 100644
--- a/web-optimle/www/src/Game.tsx
+++ b/web-optimle/www/src/Game.tsx
@@ -70,6 +70,7 @@ export function Game(props: GameProps) {
Try to guarantee a win in 2 guesses!
);
+ const [shareMsg, setShareMsg] = useState("");
const tableRef = useRef(null);
const game = useMemo(
() => wasm.Game.new(COMMON_WORDS, puzzle.history),
@@ -111,6 +112,24 @@ export function Game(props: GameProps) {
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) {
setGameState(GameState.Lost);
setHint(Not quite! The answer could've been {game.possible_word().toUpperCase()}. (Enter to try again)
);
@@ -154,7 +173,6 @@ export function Game(props: GameProps) {
} catch (e) {
console.warn("navigator.clipboard.writeText failed:", e);
}
- setHint(url);
}
const onKey = (key: string) => {
@@ -219,10 +237,6 @@ export function Game(props: GameProps) {
[puzzleType]: {
...oldStats[puzzleType],
won: true,
- guesses: [
- ...(oldStats[puzzleType].guesses || []),
- result,
- ],
},
}));
} else if (guesses.length + 1 === puzzle.history.length + MAX_GUESSES) {
@@ -319,27 +333,7 @@ export function Game(props: GameProps) {
{gameState === GameState.Won && (