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,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