From a7330c6804b118bf23d751d5a97dc4d080c93333 Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Thu, 14 Oct 2021 17:35:27 -0300 Subject: [PATCH] Counter logic done --- src/App.js | 13 +++++++++++++ src/components/Hangman/PuzzleWord/Victory.jsx | 3 ++- src/components/Scripts/AlmacenateCurrentScore.js | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/components/Scripts/AlmacenateCurrentScore.js diff --git a/src/App.js b/src/App.js index 6e5fff5..c5f73df 100644 --- a/src/App.js +++ b/src/App.js @@ -6,6 +6,7 @@ import PuzzleWord from "./components/Hangman/PuzzleWord/PuzzleWord"; import Victory from "./components/Hangman/PuzzleWord/Victory"; import Defeat from "./components/Hangman/PuzzleWord/Defeat"; import Loading from "./components/Loading"; +import AlmacenateCurrentScore from "./components/Scripts/AlmacenateCurrentScore"; function App() { @@ -19,10 +20,22 @@ function App() { const [displayApp, setDisplayApp] = useState(false) + React.useEffect(() => { + + if (localStorage.getItem('currentScore')) { + + setCurrentScore(localStorage.getItem('currentScore')) + localStorage.removeItem('currentScore') + } + + }) + if (isVictory || isDefeat) { setTimeout(() => { + AlmacenateCurrentScore(currentScore) + window.location.reload(true); }, 3000) } diff --git a/src/components/Hangman/PuzzleWord/Victory.jsx b/src/components/Hangman/PuzzleWord/Victory.jsx index 5fa9c1a..b25165f 100644 --- a/src/components/Hangman/PuzzleWord/Victory.jsx +++ b/src/components/Hangman/PuzzleWord/Victory.jsx @@ -4,7 +4,8 @@ const Victory = ({currentScore, setCurrentScore}) => { React.useEffect(() => { - setCurrentScore(currentScore + 1) + setCurrentScore(parseInt(currentScore) + 1) + }, []) return ( diff --git a/src/components/Scripts/AlmacenateCurrentScore.js b/src/components/Scripts/AlmacenateCurrentScore.js new file mode 100644 index 0000000..13c47c1 --- /dev/null +++ b/src/components/Scripts/AlmacenateCurrentScore.js @@ -0,0 +1,6 @@ +const AlmacenateCurrentScore = (currentScore) => { + + localStorage.setItem('currentScore', currentScore) +} + +export default AlmacenateCurrentScore