source: components/Alert.jsx@ b4369c8

main
Last change on this file since b4369c8 was 64dc53b, checked in by anastasovv <simon@…>, 2 years ago

Code cleanings

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[87614a5]1import React from 'react'
2
3import { useSelector, useDispatch } from 'react-redux'
4
5import { HiOutlineArrowNarrowRight } from 'react-icons/hi'
6
7import axios from 'axios'
8
9import { setBlackjack, setStyle } from '../redux/reducers/styleSlice'
[64dc53b]10import { setGame } from '../redux/reducers/playerSlice'
[87614a5]11
12const Alert = () => {
13 const playerState = useSelector(state => state.player)
14 const styleState = useSelector(state => state.style)
15
16 const dispatch = useDispatch()
17
18 const display = styleState?.style?.alert?.show ? 'flex' : 'none'
19
20 function clicked() {
21 dispatch(setStyle({
22 ...styleState.style,
23 alert: {
24 ...styleState.style.alert,
25 show: false
26 }
27 }))
28
29 if (styleState.style.alert.button.action === 'play_again') {
30 axios.get(`/api/blackjack?action=play_again&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => {
31 if (res.data?.success && res.data?.game) {
32 dispatch(setGame({
33 ...playerState.game,
34 status: res.data.game?.status,
35 playerCards: res.data.game?.playerCards,
36 dealerCards: res.data.game?.dealerCards,
37 sideBetName: res.data.game?.sideBetName,
38 }))
39
40 dispatch(setBlackjack({
41 ...styleState.blackjack,
42 inputControls: {
43 ...styleState.blackjack.inputControls,
44 initialBet: {
45 ...styleState.blackjack.inputControls.initialBet,
46 chosenCredits: parseInt(playerState.player.credits/2),
47 },
48 sideBet: {
49 ...styleState.blackjack.inputControls.sideBet,
50 chosenCredits: parseInt(0),
51 }
52 },
53 displays: {
54 ...styleState.blackjack.displays,
55 initialBet: true,
56 hitStand: false,
57 }
58 }))
59 }
60 });
61 }
62 else if (styleState.style.alert.button.action === 'continue_from_side_bet') {
63 dispatch(setBlackjack({
64 ...styleState.blackjack,
65 inputControls: {
66 ...styleState.blackjack.inputControls,
67 sideBet: {
68 ...styleState.blackjack.inputControls.sideBet,
69 chosenCredits: parseInt(0),
70 }
71 },
72 }))
73 }
74 }
75
76 return (
77 <div className="alert" style={{display: display}}>
78 <h1>{styleState.style.alert.title}</h1>
79 <h3>{styleState.style.alert.subtitle}</h3>
80 <button className='primaryButton' onClick={() => clicked()}>{styleState.style.alert.button.text} <HiOutlineArrowNarrowRight style={{marginTop: '3px', marginBottom: '-3px'}} /></button>
81 </div>
82 )
83}
84
85export default Alert
Note: See TracBrowser for help on using the repository browser.