Improve 'Add to dictionary' UI
This commit is contained in:
parent
6c7a90c421
commit
75d8db4098
2 changed files with 31 additions and 11 deletions
|
@ -107,7 +107,6 @@ export function Game(props: {
|
||||||
|
|
||||||
function addWordFn(word: string) {
|
function addWordFn(word: string) {
|
||||||
props.wasm.add_word(word);
|
props.wasm.add_word(word);
|
||||||
logDispatch(<div><em>{word} was added to dictionary.</em></div>);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const [playerLetters, trayDispatch] = useReducer(movePlayableLetters, []);
|
const [playerLetters, trayDispatch] = useReducer(movePlayableLetters, []);
|
||||||
|
@ -359,7 +358,7 @@ export function Game(props: {
|
||||||
if (message.endsWith("is not a valid word")) {
|
if (message.endsWith("is not a valid word")) {
|
||||||
// extract out word
|
// extract out word
|
||||||
const word = message.split(" ")[0];
|
const word = message.split(" ")[0];
|
||||||
logDispatch(<div><em>{message}</em><AddWordButton word={word} addWordFn={addWordFn} /></div>);
|
logDispatch(<AddWordButton word={word} addWordFn={addWordFn} />);
|
||||||
} else {
|
} else {
|
||||||
logDispatch(<div><em>{message}</em></div>);
|
logDispatch(<div><em>{message}</em></div>);
|
||||||
}
|
}
|
||||||
|
@ -410,12 +409,24 @@ export function Game(props: {
|
||||||
function AddWordButton(props: {word: string, addWordFn: (x: string) => void}) {
|
function AddWordButton(props: {word: string, addWordFn: (x: string) => void}) {
|
||||||
const [isClicked, setIsClicked] = useState<boolean>(false);
|
const [isClicked, setIsClicked] = useState<boolean>(false);
|
||||||
|
|
||||||
return <button
|
if (!isClicked) {
|
||||||
disabled={isClicked}
|
return <div>
|
||||||
onClick={() => {
|
<em>{props.word} is not a valid word.</em>
|
||||||
setIsClicked(true);
|
<button
|
||||||
props.addWordFn(props.word);
|
className="add-to-dictionary"
|
||||||
}}>
|
disabled={isClicked}
|
||||||
Add to dictionary
|
onClick={() => {
|
||||||
</button>
|
setIsClicked(true);
|
||||||
}
|
props.addWordFn(props.word);
|
||||||
|
}}>
|
||||||
|
Add to dictionary
|
||||||
|
</button>
|
||||||
|
</div>;
|
||||||
|
} else {
|
||||||
|
return <div>
|
||||||
|
<em>{props.word} was added to dictionary.</em>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,4 +270,13 @@ dialog {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
button.add-to-dictionary {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 0 0 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.log {
|
||||||
|
line-height: 1.5em;
|
||||||
}
|
}
|
Loading…
Reference in a new issue