diff --git a/src/App.js b/src/App.js
index 63506a6..e1738cd 100644
--- a/src/App.js
+++ b/src/App.js
@@ -21,11 +21,13 @@ import LettersRegistered from "./components/LettersRegistered/LettersRegistered"
import alphabet from "./General Scripts/alphabet"
import checkVictory from "./General Scripts/checkVictory";
import checkDefeat from "./General Scripts/checkDefeat";
+import BringTheWords from "./Firebase Querys/BringTheWord";
+import SelectRandomWord from "./Firebase Querys/SelectRandomWord";
function App() {
- const [displayApp, setDisplayApp] = useState(true)
+ const [displayApp, setDisplayApp] = useState(false)
- const [selectedWord, setSelectedWord] = useState('TEST')
+ const [selectedWord, setSelectedWord] = useState('')
const [correctLetters, setCorrectLetters] = useState([])
const [lettersRegistered, setLettersRegistered] = useState([])
@@ -44,7 +46,21 @@ function App() {
const [displayCategories, setDisplayCategories] = useState(false)
- React.useEffect(() => {
+ const bringWordFromFirebase = async () => {
+
+ if (!displayApp && selectedWord === '') {
+ setSelectedWord('a')
+
+ let word = await BringTheWords(language, category, selectedWord)
+ word = word.toLowerCase()
+
+ console.log(word)
+ await setSelectedWord(word)
+ await setDisplayApp(true)
+ }
+ }
+
+ React.useEffect(() => {
RecoveryCurrentScore(setCurrentScore)
RecoveryCurrentCategory(setCategory)
@@ -52,12 +68,18 @@ function App() {
DetermineUserLanguage(setLanguage)
RecoveryCurrentLanguage(setLanguage)
+ setLanguageIsReady(true)
ChangeTitle(language)
setLanguageIsReady(true)
- setSelectedWord(selectedWord.toLowerCase())
- }, [])
+ if (!displayApp && selectedWord === '' && categoryIsReady && languageIsReady) {
+ bringWordFromFirebase()
+ }
+
+ console.log(category)
+ }, [categoryIsReady])
+
React.useEffect(() => {
@@ -84,7 +106,7 @@ function App() {
else {
setHangmanFrame(hangmanFrame + 1)
- checkDefeat(setEndOfGame, hangmanFrame)
+ checkDefeat(setEndOfGame, hangmanFrame, setCorrectLetters, selectedWord)
}
}
}
@@ -103,7 +125,7 @@ function App() {
AlmacenateCategory(category)
AlmacenateLanguage(language)
- window.location.reload(true)
+ window.location.reload(false)
}, 3000)
}
@@ -149,9 +171,8 @@ function App() {
-
{
- //!displayApp ? : null
+ !displayApp ? : null
}
{endOfGame === 'Victory' ? : null}
diff --git a/src/components/Word/Firebase Querys/BringTheWord.js b/src/Firebase Querys/BringTheWord.js
similarity index 74%
rename from src/components/Word/Firebase Querys/BringTheWord.js
rename to src/Firebase Querys/BringTheWord.js
index edbe11a..d436756 100644
--- a/src/components/Word/Firebase Querys/BringTheWord.js
+++ b/src/Firebase Querys/BringTheWord.js
@@ -1,11 +1,11 @@
-import {firestore} from '../../../../Firebase/Firebase_Config'
+import {firestore} from '../Firebase/Firebase_Config'
import { getFirestore, collection, doc, getDocs, getDoc } from 'firebase/firestore/lite';
import GetRandomCategory from './GetRandomCategory';
import SelectRandomWord from './SelectRandomWord';
-const BringTheWords = async (language = false, category = false, actualWord) => {
+const BringTheWords = async (language = false, category = false, selectedWord) => {
- if (!actualWord) {
+ if (!selectedWord) {
console.log(category)
@@ -28,11 +28,10 @@ const BringTheWords = async (language = false, category = false, actualWord) =>
const data = collection(db, `hangman_words/${language}/${category}`)
const result = await getDocs(data)
- const words = await result.docs.map(doc => doc.id)
- const word = SelectRandomWord(await words)
-
- return word
-
+ const words = await result.docs.map(doc => doc.id)
+ const word = await SelectRandomWord(await words)
+ return await word
+
} catch (error) {
console.log(error)
}
diff --git a/src/components/Word/Firebase Querys/GetRandomCategory.js b/src/Firebase Querys/GetRandomCategory.js
similarity index 91%
rename from src/components/Word/Firebase Querys/GetRandomCategory.js
rename to src/Firebase Querys/GetRandomCategory.js
index 4d20559..0af7cba 100644
--- a/src/components/Word/Firebase Querys/GetRandomCategory.js
+++ b/src/Firebase Querys/GetRandomCategory.js
@@ -1,4 +1,4 @@
-import {firestore} from '../../../../Firebase/Firebase_Config'
+import {firestore} from '../Firebase/Firebase_Config'
import { getFirestore, collection, doc, getDocs, getDoc } from 'firebase/firestore/lite';
const GetRandomCategory = async () => {
diff --git a/src/components/Word/Firebase Querys/SelectRandomWord.js b/src/Firebase Querys/SelectRandomWord.js
similarity index 83%
rename from src/components/Word/Firebase Querys/SelectRandomWord.js
rename to src/Firebase Querys/SelectRandomWord.js
index 67b2f15..726d04e 100644
--- a/src/components/Word/Firebase Querys/SelectRandomWord.js
+++ b/src/Firebase Querys/SelectRandomWord.js
@@ -5,7 +5,7 @@ const SelectRandomWord = (arrayWords) => {
Math.random() * (arrayWords.length - 0) + 0
)
- return randomWord
+ return arrayWords[randomWord]
}
export default SelectRandomWord
diff --git a/src/General Scripts/checkDefeat.js b/src/General Scripts/checkDefeat.js
index 19496c0..caa5953 100644
--- a/src/General Scripts/checkDefeat.js
+++ b/src/General Scripts/checkDefeat.js
@@ -1,6 +1,7 @@
-const checkDefeat = (setEndOfGame, hangmanFrame) => {
+const checkDefeat = (setEndOfGame, hangmanFrame, setCorrectLetters, selectedWord) => {
if (hangmanFrame >= 5) {
+ setCorrectLetters([...selectedWord])
setEndOfGame('Defeat')
}
}
diff --git a/src/Storage Scripts/RecoveryCurrentCategory.js b/src/Storage Scripts/RecoveryCurrentCategory.js
index 18fa564..66f3be5 100644
--- a/src/Storage Scripts/RecoveryCurrentCategory.js
+++ b/src/Storage Scripts/RecoveryCurrentCategory.js
@@ -2,12 +2,16 @@ export const RecoveryCurrentCategory = (setCategory) => {
if (localStorage.getItem('category')) {
+ const category = localStorage.getItem('category')
+
+ console.log(category)
+ setCategory(category)
+ localStorage.removeItem('category')
+
if (localStorage.getItem('category') === 'false') {
- setCategory(false)
+ //setCategory(false)
}
- setCategory(localStorage.getItem('category'))
- localStorage.removeItem('category')
}
}
diff --git a/src/components/Categories/Categories.jsx b/src/components/Categories/Categories.jsx
index 9d69cc7..c1dc4b6 100644
--- a/src/components/Categories/Categories.jsx
+++ b/src/components/Categories/Categories.jsx
@@ -25,7 +25,7 @@ const Categories = ({language, displayCategories, category, setCategory, current
AlmacenateCurrentScore(currentScore)
AlmacenateLanguage(language)
- window.location.reload(false)
+ window.location.reload(true)
}
@@ -39,7 +39,7 @@ const Categories = ({language, displayCategories, category, setCategory, current
AlmacenateCurrentScore(currentScore)
AlmacenateCategory(category)
- window.location.reload(false)
+ window.location.reload(true)
}
React.useEffect (() => {