From e18c1da8eb25196efacb4af2b19f7eef3d9c75d4 Mon Sep 17 00:00:00 2001 From: sentosango Date: Sat, 14 Aug 2021 14:27:39 +0300 Subject: [PATCH] Implement saving entry to collection and removing from it --- .../overlays/SaveToCollectionOverlay.vue | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/components/overlays/SaveToCollectionOverlay.vue b/src/components/overlays/SaveToCollectionOverlay.vue index 3c5c407..8ece28c 100644 --- a/src/components/overlays/SaveToCollectionOverlay.vue +++ b/src/components/overlays/SaveToCollectionOverlay.vue @@ -5,7 +5,6 @@ transition-show="slide-up" transition-hide="slide-down" maximized >
-
@@ -15,7 +14,6 @@ Done
- - + {{ collection.title }} + + ✓ Saved + - @@ -60,14 +63,35 @@ export default { saveToReadLater() { console.log(`Save entry #${this.entry.id} to read later`) }, - saveToCollection(collection) { - console.log(`Save entry #${this.entry.id} to collection #${collection.id}`) + toggleSavingToCollection(collection) { + const payload = { collectionId: collection.id, entryId: this.entry.id } + const isSelectedCollection = this.$route.name === 'collection-entries' + && +this.$route.params.collectionId === collection.id + + if (this.savedToCollection(collection)) { + // todo: Bug! Removing from collection not synced with UI + this.$store.dispatch('removeEntryFromCollection', payload) + if (isSelectedCollection) { + this.$store.commit('removeEntries', [this.entry]) + } + } else { + this.$store.dispatch('saveEntryToCollection', payload) + if (isSelectedCollection) { + this.$store.commit('unshiftEntries', [this.entry]) + } + } }, }, computed: { collections () { return this.$store.state.collections }, + savedToCollection() { + console.log(this.entry) + return collection => this.entry.collections.some( + entryCollection => entryCollection.id === collection.id + ) + }, }, }