@@ -13,9 +13,12 @@ import {
13
13
import { RoundStatus } from "../../model/Round"
14
14
import { getAutoPlayCard } from "../../caches/AutoPlaySlice"
15
15
import { bestCardLead , getWorstCard } from "../../utils/GameUtils"
16
+ import { useSnackbar } from "notistack"
17
+ import parseError from "../../utils/ErrorUtils"
16
18
17
19
const AutoActionManager = ( ) => {
18
20
const dispatch = useAppDispatch ( )
21
+ const { enqueueSnackbar } = useSnackbar ( )
19
22
20
23
const gameId = useAppSelector ( getGameId )
21
24
const round = useAppSelector ( getRound )
@@ -27,8 +30,14 @@ const AutoActionManager = () => {
27
30
const isMyGo = useAppSelector ( getIsMyGo )
28
31
const isInBunker = useAppSelector ( getIsInBunker )
29
32
30
- const playCard = ( id : string , card : string ) =>
31
- dispatch ( GameService . playCard ( id , card ) ) . catch ( console . error )
33
+ const playCard = ( id : string , card : string , suppressError = false ) =>
34
+ dispatch ( GameService . playCard ( id , card ) ) . catch ( e => {
35
+ if ( ! suppressError )
36
+ enqueueSnackbar ( parseError ( e ) , {
37
+ variant : "error" ,
38
+ } )
39
+ else console . error ( e )
40
+ } )
32
41
33
42
const call = ( id : string , callAmount : number ) =>
34
43
dispatch ( GameService . call ( id , callAmount ) ) . catch ( console . error )
@@ -51,11 +60,11 @@ const AutoActionManager = () => {
51
60
round ?. suit &&
52
61
round . status === RoundStatus . PLAYING
53
62
) {
54
- if ( autoPlayCard ) playCard ( gameId , autoPlayCard )
55
- else if ( cards . length === 1 ) playCard ( gameId , cards [ 0 ] )
63
+ if ( autoPlayCard ) playCard ( gameId , autoPlayCard , true )
64
+ else if ( cards . length === 1 ) playCard ( gameId , cards [ 0 ] , true )
56
65
else if ( bestCardLead ( round ) ) {
57
66
const cardToPlay = getWorstCard ( cards , round . suit )
58
- if ( cardToPlay ) playCard ( gameId , cardToPlay . name )
67
+ if ( cardToPlay ) playCard ( gameId , cardToPlay . name , true )
59
68
}
60
69
}
61
70
} , [ gameId , round , isMyGo , cards , autoPlayCard ] )
0 commit comments