Skip to content

Commit

Permalink
Implement saving entry to collection and removing from it
Browse files Browse the repository at this point in the history
  • Loading branch information
sentosango committed Aug 14, 2021
1 parent 1876ba9 commit e18c1da
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/components/overlays/SaveToCollectionOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
transition-show="slide-up" transition-hide="slide-down" maximized
>
<div class="bg-dark">

<q-toolbar class="row">
<div class="col text-left"></div>
<q-toolbar-title class="text-center text-subtitle1 col-7">
Expand All @@ -15,7 +14,6 @@
<q-btn dense v-close-popup>Done</q-btn>
</div>
</q-toolbar>

<q-list padding>
<q-item
clickable
Expand All @@ -32,15 +30,20 @@
v-ripple
v-for="collection in collections"
:key="collection.id"
@click="saveToCollection(collection)"
@click="toggleSavingToCollection(collection)"
>
<q-item-section avatar style="min-width: auto">
<q-icon class="text-grey" name="star_outline"/>
<q-icon
:class="savedToCollection(collection) ? 'text-primary' : 'text-grey'"
:name="savedToCollection(collection) ? 'star' : 'star_outline'"
/>
</q-item-section>
<q-item-section>{{ collection.title }}</q-item-section>
<q-item-section v-if="savedToCollection(collection)" side>
<q-badge color="primary">&check; Saved</q-badge>
</q-item-section>
</q-item>
</q-list>

</div>
</q-dialog>
</template>
Expand All @@ -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
)
},
},
}
</script>

0 comments on commit e18c1da

Please sign in to comment.