From e3e506429792a673f8ae0b18d34d93355b609cd5 Mon Sep 17 00:00:00 2001 From: Zoltan Toth Date: Wed, 6 Mar 2019 08:49:54 -0500 Subject: [PATCH 1/4] Add intro screen functionality --- src/actions/start.js | 6 ++++++ src/pages/Game.jsx | 17 +++++++++++++---- src/reducers/index.js | 11 ++++++++++- src/selectors/index.js | 2 ++ src/static/constants/actions.js | 1 + src/store/index.js | 1 + 6 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/actions/start.js diff --git a/src/actions/start.js b/src/actions/start.js new file mode 100644 index 0000000..c50278f --- /dev/null +++ b/src/actions/start.js @@ -0,0 +1,6 @@ +import { START } from '../static/constants/actions'; + +export const start = payload => ({ + type: START, + payload +}); diff --git a/src/pages/Game.jsx b/src/pages/Game.jsx index b69f6c9..3cf0b53 100644 --- a/src/pages/Game.jsx +++ b/src/pages/Game.jsx @@ -2,8 +2,9 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import styled from 'styled-components'; import { connect } from 'react-redux'; +import { start } from '../actions/start'; import { restart } from '../actions/restart'; -import { getCurrent, getAnswers } from '../selectors'; +import { getIntro, getCurrent, getAnswers } from '../selectors'; import ButtonContainer from '../components/ButtonContainer'; import ProgressBar from '../components/ProgressBar'; import Code from '../components/Code'; @@ -35,7 +36,7 @@ const ShareContainer = styled.p` text-align: center; `; -const Game = ({ current, answers, style, onRestart }) => { +const Game = ({ intro, current, answers, style, onStart, onRestart }) => { let correct; if (!current) { @@ -44,13 +45,17 @@ const Game = ({ current, answers, style, onRestart }) => { return ( - {current ? ( + {intro && + + + +`; + exports[`Game page - RESULTS renders a component 1`] = ` .c0 { border: 4px solid red; diff --git a/__tests__/reducers/reducers.test.js b/__tests__/reducers/reducers.test.js index a2ef218..7e9a6f1 100644 --- a/__tests__/reducers/reducers.test.js +++ b/__tests__/reducers/reducers.test.js @@ -4,6 +4,7 @@ import { TOGGLE, TOGGLE_JS, TOGGLE_MODE, + START, RESTART } from '../../src/static/constants/actions'; @@ -38,6 +39,7 @@ const initialState = { js: 'es5', mode: 'dark', patterns: answers, + intro: true, progress: { answers: [], remaining: answers, @@ -85,6 +87,17 @@ describe('Reducers', () => { }); }); + it('should toggle INTRO', () => { + const action = { + type: START + }; + + expect(reducer(initialState, action)).toEqual({ + ...initialState, + intro: false + }); + }); + it('should handle SUBMIT', () => { const action = { type: SUBMIT, diff --git a/__tests__/selectors/selectors.test.js b/__tests__/selectors/selectors.test.js index c28bf7b..2202ae4 100644 --- a/__tests__/selectors/selectors.test.js +++ b/__tests__/selectors/selectors.test.js @@ -4,7 +4,8 @@ import { getMode, getJS, getCurrent, - getAnswers + getAnswers, + getIntro } from '../../src/selectors'; describe('Selectors', () => { @@ -14,6 +15,7 @@ describe('Selectors', () => { state = { mode: 'dark', js: 'es6', + intro: true, patterns: [0, 1, 2, 3, 4, 5, 6], progress: { answers: [0, 1, 2], @@ -46,4 +48,8 @@ describe('Selectors', () => { it('should get the JS version', () => { expect(getJS(state)).toBe('es6'); }); + + it('should get the intro value', () => { + expect(getIntro(state)).toBe(true); + }); }); From 34b2f72355f2bb291e64f02523069786163784bf Mon Sep 17 00:00:00 2001 From: Zoltan Toth Date: Wed, 6 Mar 2019 13:58:38 -0500 Subject: [PATCH 4/4] Style Intro section --- .../pages/__snapshots__/About.test.js.snap | 4 +-- .../pages/__snapshots__/Game.test.js.snap | 6 ++--- src/pages/Game.jsx | 27 ++++++++++++++++++- src/static/constants/colors.js | 1 - src/styles/themes/theme.dark.js | 4 ++- src/styles/themes/theme.light.js | 4 ++- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/__tests__/pages/__snapshots__/About.test.js.snap b/__tests__/pages/__snapshots__/About.test.js.snap index 330dda9..d2c9047 100644 --- a/__tests__/pages/__snapshots__/About.test.js.snap +++ b/__tests__/pages/__snapshots__/About.test.js.snap @@ -2,7 +2,7 @@ exports[`About page renders with a DARK theme 1`] = ` .c0 { - color: #F5F5F5; + color: #C8C8C8; } .c0 a { @@ -71,7 +71,7 @@ exports[`About page renders with a DARK theme 1`] = ` exports[`About page renders with a LIGHT theme 1`] = ` .c0 { - color: #0A000A; + color: #6F256F; } .c0 a { diff --git a/__tests__/pages/__snapshots__/Game.test.js.snap b/__tests__/pages/__snapshots__/Game.test.js.snap index 8a0ea4d..1b3ba8b 100644 --- a/__tests__/pages/__snapshots__/Game.test.js.snap +++ b/__tests__/pages/__snapshots__/Game.test.js.snap @@ -887,7 +887,7 @@ exports[`Game page - INTRO renders a @@ -1071,7 +1071,7 @@ exports[`Game page - RESULTS renders a component 1`] = `null`; exports[`Game page - RESULTS renders a component 1`] = ` .c0 { - color: #0A000A; + color: #6F256F; margin: 3rem 0; text-align: center; } diff --git a/src/pages/Game.jsx b/src/pages/Game.jsx index 3cf0b53..35b9939 100644 --- a/src/pages/Game.jsx +++ b/src/pages/Game.jsx @@ -12,6 +12,19 @@ import Result from '../components/Result'; import Percentage from '../components/Percentage'; import Button from '../components/Button'; +const Intro = styled.div` + border: 1px solid ${props => props.theme.border}; + border-radius: 4px; + color: ${props => props.theme.text}; + margin: 2rem 0; + padding: 2rem 3rem; +`; + +const StartButtonContainer = styled.div` + margin: 3rem auto 1rem; + /* text-align: center; */ +`; + const Restart = styled.div` margin: 3rem 0; text-align: center; @@ -45,7 +58,19 @@ const Game = ({ intro, current, answers, style, onStart, onRestart }) => { return ( - {intro &&