Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Rises committed Nov 23, 2023
1 parent 32d08f5 commit b6a6627
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 @@ -12,7 +14,16 @@ const App = () => {
<div className={'app-main'}>
<PokeOpening handleHasOpened={() => setIsOpeningClicked(true)} hasClicked={isOpeningClicked}/>
<PokemonList/>
<CodeKeyboardInputsEasterEgg code={konamicode}/>
<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
@@ -1,7 +1,5 @@
import React, {useEffect, useState} from 'react';
import PropTypes from 'prop-types';
import {ToastContainer, toast} from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

export const CodeKeyboardInputsEasterEgg = props => {
const [inputValue, setInputValue] = useState('');
Expand All @@ -15,14 +13,7 @@ export const CodeKeyboardInputsEasterEgg = props => {
let inputString = inputValue;

if (inputString === props.code) {
// alert('You have unlocked the Konami Code!');
toast('Easter Egg 1 found! Or should I say... Easter Pkm Egg?', {
type: 'success',
autoClose: 5000,
icon: '🥚',
closeOnClick: true,
pauseOnHover: false,
});
props.actionOnEasterEgg();
}

if (inputValue.length >= props.code.length) {
Expand All @@ -41,10 +32,10 @@ export const CodeKeyboardInputsEasterEgg = props => {
}, [handleKeyDown]);

return <>
<ToastContainer/>
</>;
};

CodeKeyboardInputsEasterEgg.propTypes = {
code: PropTypes.string.isRequired,
actionOnEasterEgg: PropTypes.func,
};
1 change: 0 additions & 1 deletion src/pages/PokemonList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,5 @@ export const PokemonList = () => {
exitDetailsPage={toggleViewDetails}
isEasterEgg={easterEggIndex >= 0}/>)}
</>)}
<ToastContainer/>
</>);
};

0 comments on commit b6a6627

Please sign in to comment.