mirror of
https://github.com/FranP-code/Hangman-game-with-React.git
synced 2025-10-13 00:42:32 +00:00
Added the firebase integration
This commit is contained in:
@@ -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 (() => {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
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) => {
|
||||
|
||||
if (!actualWord) {
|
||||
|
||||
|
||||
console.log(category)
|
||||
|
||||
if (!language) {
|
||||
|
||||
language = 'english'
|
||||
|
||||
}
|
||||
|
||||
if (!category) {
|
||||
|
||||
category = await GetRandomCategory()
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const db = getFirestore(firestore)
|
||||
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
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default BringTheWords
|
||||
@@ -1,29 +0,0 @@
|
||||
import {firestore} from '../../../../Firebase/Firebase_Config'
|
||||
import { getFirestore, collection, doc, getDocs, getDoc } from 'firebase/firestore/lite';
|
||||
|
||||
const GetRandomCategory = async () => {
|
||||
|
||||
|
||||
let categoriesList = []
|
||||
|
||||
try {
|
||||
|
||||
const db = getFirestore(firestore)
|
||||
const data = collection(db, `categories`)
|
||||
const result = await getDocs(data)
|
||||
|
||||
result.docs.map(doc => categoriesList.push(doc.id.toLowerCase()))
|
||||
|
||||
const randomNumber = Math.trunc(
|
||||
|
||||
Math.random() * (categoriesList.length - 0) + 0
|
||||
)
|
||||
|
||||
return categoriesList[randomNumber]
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
export default GetRandomCategory
|
||||
@@ -1,11 +0,0 @@
|
||||
const SelectRandomWord = (arrayWords) => {
|
||||
|
||||
const randomWord = Math.trunc(
|
||||
|
||||
Math.random() * (arrayWords.length - 0) + 0
|
||||
)
|
||||
|
||||
return randomWord
|
||||
}
|
||||
|
||||
export default SelectRandomWord
|
||||
Reference in New Issue
Block a user