Skip to content

Commit

Permalink
Dismiss card help text on click
Browse files Browse the repository at this point in the history
See #10
  • Loading branch information
c-w committed Nov 27, 2020
1 parent bda9d37 commit 916602e
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/frontend/boards/fitf/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import classNames from 'classnames';
import { isMoveInvalid } from '../../../shared/games/fitf';
Expand Down Expand Up @@ -38,6 +38,28 @@ function Card({ card, compact, won, isNew, isOld }) {
);
}

/**
* @param {object} props
* @param {Card?} props.card
*/
function HelpText({ card }) {
const [shown, setShown] = useState(true);

const onClick = useCallback(() => {
setShown(false);
}, [setShown]);

if (!card || !shown) {
return null;
}

return (
<aside onClick={onClick}>
{CARD_TEXTS[card.rank]}
</aside>
)
}

/**
* @param {object} props
* @param {G} props.G
Expand Down Expand Up @@ -113,7 +135,7 @@ export default function Board({ G, ctx, playerID, moves, matchData }) {
const trump = last(G.trumps);
const previousTrump = trump.turn > 0 && ctx.turn - trump.turn <= 1 ? G.trumps[G.trumps.length - 2] : null;
const lastTrick = isEndOfRound && showEndOfRoundScreen ? last(last(G.history)) : G.tricks.length >= 1 ? last(G.tricks) : null;
const helpText = chosen.length > 0 ? CARD_TEXTS[player.hand[chosen[0]].rank] : null;
const firstPickedCard = chosen.length > 0 ? player.hand[chosen[0]] : null;

useEffect(() => {
if (isEndOfRound) {
Expand Down Expand Up @@ -262,11 +284,7 @@ export default function Board({ G, ctx, playerID, moves, matchData }) {
)}
</ol>
</div>
{helpText && (
<aside>
{helpText}
</aside>
)}
<HelpText card={firstPickedCard} key={`${firstPickedCard?.suit}-${firstPickedCard?.rank}`} />
</form>
);
}

0 comments on commit 916602e

Please sign in to comment.