There's a simple function that sets the loader value to true and then, when the function finishes, it sets it back to false. However, I'm facing an issue where my async/await functions are not properly awaiting the code that involves firebase batch writes. Here's a snippet of my code:
const updateNegotiation = async title => {
negotiationLoader.value = true
await store.dispatch('actionUpdateNegotiation', {
negotiation: listFromDialog.value,
title: title,
loader: negotiationLoader.value
})
negotiationLoader.value = false // the loader's value should be set to false after await
}
Additionally, here is the firebase function that uses batch writes:
//vuex
async actionUpdateNegotiation({commit}, deal){
const batch = db.batch()
const reference = db.collection('negotiations')
.doc(moduleUser.state.user.email)
.collection('deals')
const setRef = reference.doc(deal.title)
.collection('clients')
.doc(deal.negotiation.id)
batch.set(setRef, deal.negotiation)
batch.update(setRef, {
...deal.negotiation,
status: deal.title
})
const deleteRef = reference.doc(deal.negotiation.status)
.collection('clients')
.doc(deal.negotiation.id)
batch.delete(deleteRef)
try{
batch.commit()
return {
res: false
}
} catch (error) {
console.log(error);
return{
error,
res: true
}
}
}