Skip to content

Instantly share code, notes, and snippets.

@programarivm
Created July 31, 2022 14:11
Show Gist options
  • Save programarivm/c37b3c3b96e4e6f4a2f666237fcdd84e to your computer and use it in GitHub Desktop.
Save programarivm/c37b3c3b96e4e6f4a2f666237fcdd84e to your computer and use it in GitHub Desktop.
src/features/playMode/StartedButtonsPlayMode.js
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { Button, ButtonGroup } from '@mui/material/';
import { makeStyles } from '@mui/styles';
import { openDrawOfferDialog } from '../../features/dialog/offerDrawDialogSlice';
import { openResignAcceptDialog } from '../../features/dialog/acceptResignDialogSlice';
import { openTakebackOfferDialog } from '../../features/dialog/offerTakebackDialogSlice';
import { MODE_PLAY } from '../../features/modeConstants';
const useStyles = makeStyles({
buttonGroup: {
marginTop: 15,
},
});
const StartedButtonsPlayMode = () => {
const classes = useStyles();
const state = useSelector(state => state);
const dispatch = useDispatch();
if (state.mode.name === MODE_PLAY) {
if (state.mode.play.accepted) {
if (
!state.board.isMate &&
!state.mode.play.draw &&
!state.mode.play.resign &&
!state.mode.play.leave &&
!state.mode.play.timer.over
) {
return (
<ButtonGroup
className={classes.buttonGroup}
size="small"
aria-label="Game Buttons"
orientation="vertical"
fullWidth={true}
>
<Button
disabled={!state.board.movetext}
onClick={() => dispatch(openTakebackOfferDialog())}
>
Propose a takeback
</Button>
<Button onClick={() => dispatch(openDrawOfferDialog())}>
Offer draw
</Button>
<Button onClick={() => dispatch(openResignAcceptDialog())}>
Resign
</Button>
</ButtonGroup>
);
}
}
}
return null;
}
export default StartedButtonsPlayMode;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment