Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

[issue#707] Add button Hint #743

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
/*eslint "linebreak-style": ["error", "windows"]*/
{
"parser": "babel-eslint",
"extends": ["airbnb", "prettier"],
"plugins": ["react", "jsx-a11y", "import", "prettier"],
"linebreak-style": [
"error",
"windows"
],
"extends": [
"airbnb",
"prettier"
],
"plugins": [
"react",
"jsx-a11y",
"import",
"prettier"
],
"env": {
"jest": true,
"browser": true
},
"rules": {
"prettier/prettier": ["error"],
"prettier/prettier": [
"error"
],
"no-use-before-define": 0,
"lines-between-class-members": 0,
"import/prefer-default-export": 0
Expand All @@ -16,4 +31,4 @@
"document": true,
"Event": true
}
}
}
32 changes: 26 additions & 6 deletions src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ body,
grid-row-start: 2;
}

.hint-button {
padding: 0px;
cursor: pointer;
background: transparent;
border-width: 2px;
border-style: dashed;
border-color: #fff;
width: 52px;
height: 52px;
position: absolute;
top: 100px;
left: 30px;
font-size: 20px;
}

.confetti-canon {
position: absolute;
left: 50%;
Expand Down Expand Up @@ -284,7 +299,7 @@ progress[value]::-webkit-progress-value {
}

.animation--shake {
animation: shake 0.82s cubic-bezier(.36, .07, .19, .97) both;
animation: shake 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
perspective: 1000px;
Expand Down Expand Up @@ -319,19 +334,24 @@ progress[value]::-webkit-progress-value {
}

@keyframes shake {
10%, 90% {
10%,
90% {
transform: translate3d(-1px, 0, 0);
}

20%, 80% {
20%,
80% {
transform: translate3d(2px, 0, 0);
}

30%, 50%, 70% {
30%,
50%,
70% {
transform: translate3d(-4px, 0, 0);
}

40%, 60% {
40%,
60% {
transform: translate3d(4px, 0, 0);
}
}
}
4 changes: 4 additions & 0 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ChangeButton } from './components/ChangeButton';
import { Rebus } from './components/Rebus';
import { ProgressBar } from './components/ProgressBar';
import { Hint } from './components/Hint';
import { HintButton } from './components/HintButton';

import { actions } from './store';
import '../css/main.css';
Expand Down Expand Up @@ -50,6 +51,9 @@ export function init() {
className: 'change-button--next',
onClick: () => actions.next()
}),
HintButton({
onClick: () => actions.toggleHint()
}),
Hint(),
ProgressBar()
),
Expand Down
7 changes: 4 additions & 3 deletions src/js/components/Hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ export function Hint(props) {
return connect(
createComponent({
props,
render({ current, rebuses, incorrectAnswerCount }) {
render({ current, rebuses, incorrectAnswerCount, flagHint }) {
const INCORRECT_ANSWER_MAX_COUNT = 3;
const HINT_SYMBOL = '💡';
const rebus = rebuses[current];
const showHint =
incorrectAnswerCount >= INCORRECT_ANSWER_MAX_COUNT && !rebus.isAnswered && rebus.hint;
return `
(incorrectAnswerCount >= INCORRECT_ANSWER_MAX_COUNT && !rebus.isAnswered && rebus.hint) ||
flagHint == 1;
return `
${
showHint
? `<span class="rebus__hint">
Expand Down
15 changes: 15 additions & 0 deletions src/js/components/HintButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createComponent } from '../mini';

export function HintButton(props) {
return createComponent({
props,
render() {
const HINT_SYMBOL = '💡';
return `
<button class="hint-button">
${HINT_SYMBOL}
</button>
`;
}
});
}
9 changes: 8 additions & 1 deletion src/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ export const actionsCreators = {
return { animation: 'shake' };
}
return {};
},
toggleHint: ({ flagHint }) => {
if (flagHint == 0) {
return { flagHint: 1 };
}
return { flagHint: 0 };
}
};

export const initialState = {
current: 0,
animation: 'none',
rebuses: getRebuses(),
incorrectAnswerCount: 0
incorrectAnswerCount: 0,
flagHint: 0
};

export const { connect, actions } = createStore(initialState, actionsCreators);