Skip to content

Commit

Permalink
Add show total button
Browse files Browse the repository at this point in the history
  • Loading branch information
Teemeam committed Apr 3, 2022
1 parent b264444 commit 24f8c88
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maxi-yatzy",
"version": "1.2.0",
"version": "1.3.0",
"engines": {
"node": ">=12.14.1"
},
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/Button/index.styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const Button = styled.button`
padding: 8px 12px;
border: 2px solid black;
border-radius: ${ props => props.loadDataButton ? '0 10px 10px 0' : '10px' };
background-color: ${ props => props.showLoadSaveMenu ? 'black' : 'white' };
color: ${ props => props.showLoadSaveMenu ? 'white' : 'black' };
background-color: ${ props => props.showLoadSaveMenu || props.showTotal ? 'black' : 'white' };
color: ${ props => props.showLoadSaveMenu || props.showTotal ? 'white' : 'black' };
cursor: pointer;
:hover {
background-color: black;
Expand Down
11 changes: 7 additions & 4 deletions src/js/components/Combinations/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import chance from './../../../img/chance.svg';
import * as s from './index.styled.js';

export const Combinations = (props) => {
const { playerCount } = props;
const { playerCount, showTotal } = props;

return (<s.Container playerCount={ playerCount }>
<table>
Expand Down Expand Up @@ -173,14 +173,17 @@ export const Combinations = (props) => {
<tr>
<td className='maxi-yatzy'>maxi yatzy</td>
</tr>
<tr>
<td className='total'>TOTAL</td>
</tr>
{ showTotal && (
<tr>
<td className='total'>TOTAL</td>
</tr>
)}
</tbody>
</table>
</s.Container>);
};

Combinations.propTypes = {
playerCount: PropTypes.number.isRequired,
showTotal: PropTypes.bool.isRequired,
}
14 changes: 9 additions & 5 deletions src/js/components/PlayerColumn/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const PlayerColumn = (props) => {
bonus,
total,
focusedInput,
showTotal,
handleFocus,
handleBlur,
handleKeyDown,
Expand Down Expand Up @@ -330,11 +331,13 @@ export const PlayerColumn = (props) => {
onChange={ e => updateScore(player, 19, e.target.value) }/>
</td>
</tr>
<tr>
<td className='total'>
{ total }
</td>
</tr>
{ showTotal && (
<tr>
<td className='total'>
{ total }
</td>
</tr>
)}
</tbody>
</table>
</s.Container>);
Expand All @@ -348,6 +351,7 @@ PlayerColumn.propTypes = {
bonus: PropTypes.number.isRequired,
total: PropTypes.number.isRequired,
focusedInput: PropTypes.array.isRequired,
showTotal: PropTypes.bool.isRequired,
handleFocus: PropTypes.func.isRequired,
handleBlur: PropTypes.func.isRequired,
handleKeyDown: PropTypes.func.isRequired,
Expand Down
19 changes: 18 additions & 1 deletion src/js/components/ScoreCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GameMenu } from './../GameMenu/index.jsx';
import { PlayerNames } from './../PlayerNames/index.jsx';
import { Combinations } from './../Combinations/index.jsx';
import { PlayerColumn } from './../PlayerColumn/index.jsx';
import { ShowTotalButton } from './../ShowTotalButton/index.jsx';

/* Styles */
import * as s from './index.styled.js';
Expand Down Expand Up @@ -46,6 +47,7 @@ export const ScoreCard = (props) => {
});
const [resetRequested, setResetRequested] = useState(false);
const [focusedInput, setFocusedInput] = useState([null, null]);
const [showTotal, setShowTotal] = useState(true);

/* Get game data from localStorage */
useEffect(() => {
Expand Down Expand Up @@ -212,6 +214,15 @@ export const ScoreCard = (props) => {
handleRequest();
}

/* Handle show total */
function handleShowTotal() {
if (showTotal) {
setShowTotal(false)
} else {
setShowTotal(true)
}
}

return (<s.Container>
<GameMenu
data={ data }
Expand All @@ -227,7 +238,7 @@ export const ScoreCard = (props) => {
updateName={ updateName }/>

<div className='tbody-wrapper'>
<Combinations playerCount={ playerCount }/>
<Combinations playerCount={ playerCount } showTotal={ showTotal }/>

{/* Player 1 column */}
{ playerCount > 0 &&
Expand All @@ -239,6 +250,7 @@ export const ScoreCard = (props) => {
bonus={ data[0].bonus }
total={ data[0].total }
focusedInput={ focusedInput }
showTotal={ showTotal }
handleFocus={ handleFocus }
handleBlur={ handleBlur }
handleKeyDown={ handleKeyDown }
Expand All @@ -255,6 +267,7 @@ export const ScoreCard = (props) => {
bonus={ data[1].bonus }
total={ data[1].total }
focusedInput={ focusedInput }
showTotal={ showTotal }
handleFocus={ handleFocus }
handleBlur={ handleBlur }
handleKeyDown={ handleKeyDown }
Expand All @@ -271,6 +284,7 @@ export const ScoreCard = (props) => {
bonus={ data[2].bonus }
total={ data[2].total }
focusedInput={ focusedInput }
showTotal={ showTotal }
handleFocus={ handleFocus }
handleBlur={ handleBlur }
handleKeyDown={ handleKeyDown }
Expand All @@ -287,12 +301,15 @@ export const ScoreCard = (props) => {
bonus={ data[3].bonus }
total={ data[3].total }
focusedInput={ focusedInput }
showTotal={ showTotal }
handleFocus={ handleFocus }
handleBlur={ handleBlur }
handleKeyDown={ handleKeyDown }
updateScore={ updateScore }/>
}
</div>

<ShowTotalButton showTotal={ showTotal } handleShowTotal={ handleShowTotal }/>
</s.Container>);
};

Expand Down
19 changes: 19 additions & 0 deletions src/js/components/ShowTotalButton/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';

/* Styles */
import * as s from './index.styled.js';
import { Button } from './../Button/index.styled.js';

export const ShowTotalButton = (props) => {
const { showTotal, handleShowTotal } = props;

return (<s.Container>
<Button showTotal={ showTotal } onClick={ handleShowTotal }>Show total</Button>
</s.Container>);
};

ShowTotalButton.propTypes = {
showTotal: PropTypes.bool.isRequired,
handleShowTotal: PropTypes.func.isRequired,
}
8 changes: 8 additions & 0 deletions src/js/components/ShowTotalButton/index.styled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import styled from '@emotion/styled';

export const Container = styled.div`
position: relative;
width: 100%;
margin: 30px 0 0 0;
text-align: center;
`;

0 comments on commit 24f8c88

Please sign in to comment.