Changeset b13f93b for components


Ignore:
Timestamp:
07/03/22 22:59:15 (2 years ago)
Author:
anastasovv <simon@…>
Branches:
main
Children:
3a783f2
Parents:
ace7865
Message:

Made poker tables system and round 1

Location:
components
Files:
7 added
4 edited

Legend:

Unmodified
Added
Removed
  • components/LoginScreen.jsx

    race7865 rb13f93b  
    7777        axios.post(`/api/postgre`, {
    7878            action: 'login',
    79             // username: 'drama',
    80             // password: 'drama'
    8179            username: styleState.style.loginScreenInfo.username,
    8280            password: styleState.style.loginScreenInfo.password,
  • components/Notification.jsx

    race7865 rb13f93b  
    2424    }
    2525
     26    if (styleState.style.notification.show === true) {
     27        setTimeout(() => {
     28            close();
     29        }, 3000);
     30    }
     31
    2632    return (
    2733        <div className="notification" style={{display: display, backgroundColor: bg}}>
  • components/poker/PokerHeader.jsx

    race7865 rb13f93b  
    33import Link from 'next/link'
    44
     5import { useRouter } from 'next/router'
     6
    57import { AiOutlineArrowLeft } from 'react-icons/ai'
    68
     9import { useEffect } from 'react'
    710import { useDispatch, useSelector } from 'react-redux'
    811
     12import { setPlayer, setPokerGame, setSocket } from '../../redux/reducers/playerSlice'
     13import { setStyle } from '../../redux/reducers/styleSlice'
     14
     15import axios from 'axios';
     16
    917const PokerHeader = () => {
     18    const dispatch = useDispatch();
     19
     20    const router = useRouter();
     21
    1022    const playerState = useSelector(state => state.player);
    1123    const styleState = useSelector(state => state.style);
     24
     25    useEffect(() => async function() {
     26        // display loading screen
     27        dispatch(setStyle({
     28            ...styleState.style,
     29            displayLoadingScreen: true,
     30        }));
     31
     32        let interval = setInterval(() => {
     33            axios.get(`/api/poker?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => {
     34                if (res.data?.success) {
     35                    dispatch(setPokerGame(res.data?.pokerGame))
     36                }
     37            });
     38        }, 3000);
     39
     40        axios.get(`/api/poker?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => {
     41            if (res.data?.success) {
     42                dispatch(setPlayer({
     43                    ...playerState.player,
     44                    displayName: res.data?.displayName,
     45                    session_id: res.data?.session_id,
     46                    credits: res.data?.credits,
     47                }));
     48
     49                dispatch(setStyle({
     50                    ...styleState.style,
     51                    displayLoadingScreen: false,
     52                }))
     53            }
     54            else {
     55                dispatch(setStyle({
     56                    ...styleState.style,
     57                    notification: {
     58                        show: true,
     59                        text: 'Please login in order to play poker.',
     60                        status: 'error',
     61                    },
     62                    displayLoadingScreen: false,
     63                }))
     64
     65                router.push('/');
     66            }
     67        });
     68       
     69        return () => clearInterval(interval);
     70    }, [playerState.pokerGame.player.table])
    1271
    1372    return (
  • components/poker/PokerSections.jsx

    race7865 rb13f93b  
    11import React from 'react'
    22
     3import Cards from './sections/Cards'
     4import CardsInTheMiddle from './sections/CardsInTheMiddle'
     5import Chairs from './sections/Chairs'
     6import Messages from './sections/Messages'
     7import PlayButtons from './sections/PlayButtons'
     8import PickATable from './sections/PickATable'
     9
     10import { useSelector, useDispatch } from 'react-redux'
     11
    312const PokerSections = () => {
    4   return (
    5     <div>
    6        
    7     </div>
    8   )
     13  const playerState = useSelector(state => state.player);
     14
     15  if (playerState.pokerGame.player.table.length > 0) {
     16    return (
     17      <>
     18          <Messages/>
     19
     20          <Chairs/>
     21
     22          <Cards/>
     23
     24          <CardsInTheMiddle/>
     25
     26          <PlayButtons/>
     27      </>
     28    )
     29  }
     30  else {
     31    return (
     32      <>
     33        <PickATable/>
     34      </>
     35    )
     36  }
    937}
    1038
Note: See TracChangeset for help on using the changeset viewer.