Added the firebase integration

This commit is contained in:
2021-10-19 18:38:20 -03:00
parent 9f9cf73bf3
commit 05c033b86e
7 changed files with 50 additions and 25 deletions

View File

@@ -0,0 +1,41 @@
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, selectedWord) => {
if (!selectedWord) {
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 = await SelectRandomWord(await words)
return await word
} catch (error) {
console.log(error)
}
}
}
export default BringTheWords