Skip to content

Commit

Permalink
fixed favorite animal. It needed to trigger animal update sync
Browse files Browse the repository at this point in the history
  • Loading branch information
omiras committed Mar 8, 2021
1 parent ff80ad0 commit 0347383
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/AnimalSlide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default {
setTimeout(function () {
that.$store.dispatch("addFavoriteAnimal", animal);
that.$store.dispatch("updateAnimals", animal.id);
that.$store.dispatch("triggerAnimalUpdate", animal.id);
}, that.animationDuration);
},
onRemove(animalId) {
Expand Down Expand Up @@ -109,7 +109,7 @@ export default {
this.$emit("removeSelected", animalId);
setTimeout(function () {
that.$store.dispatch("addRemovedAnimal", animalId);
that.$store.dispatch("updateAnimals", animalId);
that.$store.dispatch("triggerAnimalUpdate", animalId);
}, that.animationDuration);
},
},
Expand Down
13 changes: 12 additions & 1 deletion src/firebaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ async function deleteDocument(id) {
})
}

async function triggerAnimalUpdateDB(id) {
const ref = db.collection('animals').doc(id);

await ref.update({
updatedDate: new Date()
})

return ref
}

async function addFavorite(id_animal, id_user) {
const ref = db.collection("users").doc(id_user);

Expand Down Expand Up @@ -257,7 +267,8 @@ export {
deleteDocument,
deleteDocumentFromAnimalPhoto,
updateAnimalDocument,
getSyncData
getSyncData,
triggerAnimalUpdateDB
}

//Create function recieves user and password and create such user in the database. If everythuing goes well it should updateProfile
8 changes: 7 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
deleteDocument,
deleteDocumentFromAnimalPhoto,
updateAnimalDocument,
getSyncData
getSyncData,
triggerAnimalUpdateDB
} from '../firebaseConfig.js'

const store = createStore({
Expand Down Expand Up @@ -458,6 +459,11 @@ const store = createStore({

},

async triggerAnimalUpdate(context, payload) {
await triggerAnimalUpdateDB(payload)

},

async getAnimal(context, payload) {
const animal = await getDataById(payload, 'animals')

Expand Down
3 changes: 2 additions & 1 deletion src/views/FavouriteAnimals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ export default {
},
computed: {
animalList() {
console.log("Ejecutando computed de FavoriteAnimals")
console.log("Ejecutando computed de FavoriteAnimals:", this.$store.getters.getFavoriteAnimals)
return this.$store.getters.getFavoriteAnimals;
},
},
};
</script>
<style scoped>
Expand Down

0 comments on commit 0347383

Please sign in to comment.