Skip to content

Commit

Permalink
Simplifying double click
Browse files Browse the repository at this point in the history
This will fix the issue where the last card isn't removed from your hand when played.
  • Loading branch information
daithihearn committed Feb 26, 2023
1 parent 41d47f2 commit 7b4be6b
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/components/Game/MyCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ import {
} from "../../caches/AutoPlaySlice"
import parseError from "../../utils/ErrorUtils"

interface DoubleClickTracker {
time: number
card: string
}

const MyCards: React.FC = () => {
const dispatch = useAppDispatch()
const gameId = useAppSelector(getGameId)
Expand All @@ -51,9 +46,6 @@ const MyCards: React.FC = () => {

const { enqueueSnackbar } = useSnackbar()

const [doubleClickTracker, updateDoubleClickTracker] =
useState<DoubleClickTracker>()

const selectedCards = useAppSelector(getSelectedCards)

const playButtonEnabled = useMemo(
Expand Down Expand Up @@ -85,7 +77,10 @@ const MyCards: React.FC = () => {
)

const handleSelectCard = useCallback(
(card: SelectableCard) => {
(
card: SelectableCard,
event: React.MouseEvent<HTMLImageElement, MouseEvent>,
) => {
if (!cardsSelectable || card.name === BLANK_CARD.name) {
return
}
Expand All @@ -95,24 +90,17 @@ const MyCards: React.FC = () => {
if (autoPlayCard === card.name) {
dispatch(clearAutoPlay())
dispatch(clearSelectedCards())
} else if (
doubleClickTracker?.card === card.name &&
Date.now() - doubleClickTracker.time < 500
) {
} else if (event.detail === 2) {
dispatch(toggleAutoPlay(card))
} else {
dispatch(toggleUniqueSelect(card))
dispatch(clearAutoPlay())
updateDoubleClickTracker({
card: card.name,
time: Date.now(),
})
}
} else {
dispatch(toggleSelect(card))
}
},
[round, myCards, autoPlayCard, doubleClickTracker],
[round, myCards, autoPlayCard],
)

const handleOnDragEnd = useCallback(
Expand Down Expand Up @@ -209,9 +197,10 @@ const MyCards: React.FC = () => {
{...provided.dragHandleProps}>
<CardImg
alt={card.name}
onClick={() =>
onClick={event =>
handleSelectCard(
card,
event,
)
}
src={`/cards/thumbnails/${card.name}.png`}
Expand Down Expand Up @@ -263,9 +252,10 @@ const MyCards: React.FC = () => {
{...provided.dragHandleProps}>
<CardImg
alt={card.name}
onClick={() =>
onClick={event =>
handleSelectCard(
card,
event,
)
}
src={`/cards/thumbnails/${card.name}.png`}
Expand Down

0 comments on commit 7b4be6b

Please sign in to comment.