diff --git a/src/components/Game/Buying.tsx b/src/components/Game/Buying.tsx
index ae774d6..a760221 100644
--- a/src/components/Game/Buying.tsx
+++ b/src/components/Game/Buying.tsx
@@ -1,15 +1,4 @@
-import {
- Modal,
- ModalBody,
- ModalHeader,
- Button,
- ButtonGroup,
- Form,
- CardImg,
- CardBody,
- CardGroup,
- Card,
-} from "reactstrap"
+import { Button, ButtonGroup, Form, CardBody } from "reactstrap"
import { useCallback, useMemo, useState } from "react"
@@ -27,6 +16,7 @@ import {
removeAllFromHand,
riskOfMistakeBuyingCards,
} from "../../utils/GameUtils"
+import ThrowCardsWarningModal from "./ThrowCardsWarningModal"
const Buying = () => {
const dispatch = useAppDispatch()
@@ -45,8 +35,8 @@ const Buying = () => {
)
const buyCards = useCallback(
- (e: React.FormEvent) => {
- e.preventDefault()
+ (e?: React.FormEvent) => {
+ if (e) e.preventDefault()
if (riskOfMistakeBuyingCards(suit!, selectedCards, myCards)) {
showCancelDeleteCardsDialog()
} else {
@@ -80,55 +70,13 @@ const Buying = () => {
-
-
- {" "}
- Are you sure you want to throw these cards away?
-
-
-
-
-
- {removeAllFromHand(selectedCards, myCards).map((card) => (
-
- ))}
-
-
-
-
-
-
-
-
-
-
-
-
+
) : null}
diff --git a/src/components/Game/SelectSuit.tsx b/src/components/Game/SelectSuit.tsx
index 3c0316a..ef9bd6e 100644
--- a/src/components/Game/SelectSuit.tsx
+++ b/src/components/Game/SelectSuit.tsx
@@ -1,14 +1,4 @@
-import {
- Modal,
- ModalBody,
- ModalHeader,
- Button,
- ButtonGroup,
- Card,
- CardImg,
- CardBody,
- CardGroup,
-} from "reactstrap"
+import { Button, ButtonGroup, CardBody } from "reactstrap"
import { useCallback, useEffect, useState } from "react"
@@ -20,6 +10,7 @@ import { Suit } from "../../model/Suit"
import { useSnackbar } from "notistack"
import { getMyCardsWithoutBlanks } from "../../caches/MyCardsSlice"
import { removeAllFromHand } from "../../utils/GameUtils"
+import ThrowCardsWarningModal from "./ThrowCardsWarningModal"
const SelectSuit = () => {
const dispatch = useAppDispatch()
@@ -63,6 +54,14 @@ const SelectSuit = () => {
[gameId, selectedCards]
)
+ const selectFromDummyCallback = useCallback(() => {
+ if (selectedSuit) {
+ dispatch(
+ GameService.chooseFromDummy(gameId!, selectedCards, selectedSuit)
+ ).catch((e: Error) => enqueueSnackbar(e.message, { variant: "error" }))
+ }
+ }, [gameId, selectedCards, selectedSuit])
+
const hideCancelSelectFromDummyDialog = useCallback(() => {
setSelectedSuit(undefined)
setPossibleIssues(false)
@@ -140,63 +139,15 @@ const SelectSuit = () => {
- {possibleIssue && selectedSuit ? (
-
-
- {" "}
- Are you sure you want to throw these cards away?
-
-
-
-
-
- {removeAllFromHand(selectedCards, myCards).map(
- (card) => (
-
- )
- )}
-
-
-
-
-
-
-
-
-
-
-
-
- ) : null}
+ {selectedSuit && (
+
+ )}
) : (
diff --git a/src/components/Game/ThrowCardsWarningModal.tsx b/src/components/Game/ThrowCardsWarningModal.tsx
new file mode 100644
index 0000000..4a72053
--- /dev/null
+++ b/src/components/Game/ThrowCardsWarningModal.tsx
@@ -0,0 +1,91 @@
+import React, { useCallback } from "react"
+import {
+ Modal,
+ ModalBody,
+ ModalHeader,
+ Button,
+ ButtonGroup,
+ CardImg,
+ CardBody,
+ CardGroup,
+ Card as CardComponent,
+} from "reactstrap"
+import { Card } from "../../model/Cards"
+import { Suit } from "../../model/Suit"
+
+interface ModalOpts {
+ modalVisible: boolean
+ cancelCallback: () => void
+ continueCallback: () => void
+ suit: Suit
+ cards: Card[]
+}
+
+const ThrowCardsWarningModal: React.FC = ({
+ modalVisible,
+ cancelCallback,
+ continueCallback,
+ suit,
+ cards,
+}) => {
+ const callContinue = useCallback(
+ (event: React.SyntheticEvent) => {
+ event.preventDefault()
+ continueCallback()
+ },
+ []
+ )
+ return (
+ cancelCallback()}
+ isOpen={modalVisible}
+ >
+
+ {" "}
+ Are you sure you want to throw these cards away?
+
+
+
+
+
+ {cards.map((card) => (
+
+ ))}
+
+
+
+
+
+
+
+
+
+
+
+
+ )
+}
+
+export default ThrowCardsWarningModal