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
>
-
-
+
{{ 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
+ )
+ },
},
}