Organizated the files

This commit is contained in:
2021-10-19 14:30:18 -03:00
parent b9128d737e
commit 9425e27bd3
15 changed files with 50 additions and 24 deletions

View File

@@ -0,0 +1,40 @@
import {firestore} from '../../../../Firebase/Firebase_Config'
import { getFirestore, collection, doc, getDocs, getDoc } from 'firebase/firestore/lite';
import GetRandomCategory from './GetRandomCategory';
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)
return words
} catch (error) {
console.log(error)
}
}
}
export default BringTheWords

View File

@@ -0,0 +1,29 @@
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