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:
41
src/Firebase Querys/BringTheWord.js
Normal file
41
src/Firebase Querys/BringTheWord.js
Normal 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
|
||||
Reference in New Issue
Block a user