Skip to content

Commit

Permalink
Merge pull request #65 from Im-Rises/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Im-Rises committed Nov 24, 2023
2 parents 8201738 + b6a6627 commit bba14c4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import './app.scss';
import React from 'react';
import PokeOpening from './components/Opening/PokeOpening.jsx';
import {PokemonList} from './pages/PokemonList.jsx';
import {CodeKeyboardInputsEasterEgg} from './components/CodeKeyboardInputsEasterEgg/CodeKeyboardInputsEasterEgg.jsx';
import konamicode from './constants/code-easteregg.js';
import {ToastContainer, toast} from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

const App = () => {
const [isOpeningClicked, setIsOpeningClicked] = React.useState(false);
Expand All @@ -10,6 +14,16 @@ const App = () => {
<div className={'app-main'}>
<PokeOpening handleHasOpened={() => setIsOpeningClicked(true)} hasClicked={isOpeningClicked}/>
<PokemonList/>
<CodeKeyboardInputsEasterEgg code={konamicode} actionOnEasterEgg={() => {
toast('Easter Egg 1 found! Or should I say... Easter Pkm Egg?', {
type: 'success',
autoClose: 5000,
icon: '🥚',
closeOnClick: true,
pauseOnHover: false,
});
}}/>
<ToastContainer/>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, {useEffect, useState} from 'react';
import PropTypes from 'prop-types';

export const CodeKeyboardInputsEasterEgg = props => {
const [inputValue, setInputValue] = useState('');

const handleKeyDown = event => {
const {keyCode} = event;
setInputValue(inputValue + keyCode);
};

useEffect(() => {
let inputString = inputValue;

if (inputString === props.code) {
props.actionOnEasterEgg();
}

if (inputValue.length >= props.code.length) {
inputString = inputString.slice(1);
}

setInputValue(inputString);
}, [inputValue, props.code]);

useEffect(() => {
document.addEventListener('keydown', handleKeyDown);

return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [handleKeyDown]);

return <>
</>;
};

CodeKeyboardInputsEasterEgg.propTypes = {
code: PropTypes.string.isRequired,
actionOnEasterEgg: PropTypes.func,
};
3 changes: 3 additions & 0 deletions src/constants/code-easteregg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const konamicode = '38384040373937396665';

export default konamicode;
3 changes: 1 addition & 2 deletions src/pages/PokemonList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const PokemonList = () => {

// If one of the Pokémon Easter Egg name is entered
if (easterEggPokemonData.some(pkm => pkm.pokemonName === search)) {
toast('Easter Egg found! Or should I say... Easter Pkm Egg?', {
toast('Easter Egg 1 found! Or should I say... Easter Pkm Egg?', {
type: 'success',
autoClose: 5000,
icon: '🥚',
Expand Down Expand Up @@ -166,6 +166,5 @@ export const PokemonList = () => {
exitDetailsPage={toggleViewDetails}
isEasterEgg={easterEggIndex >= 0}/>)}
</>)}
<ToastContainer/>
</>);
};

0 comments on commit bba14c4

Please sign in to comment.