55 transition-show =" slide-up" transition-hide =" slide-down" maximized
66 >
77 <div class =" bg-dark" >
8-
98 <q-toolbar class =" row" >
109 <div class =" col text-left" ></div >
1110 <q-toolbar-title class =" text-center text-subtitle1 col-7" >
1514 <q-btn dense v-close-popup >Done</q-btn >
1615 </div >
1716 </q-toolbar >
18-
1917 <q-list padding >
2018 <q-item
2119 clickable
3230 v-ripple
3331 v-for =" collection in collections"
3432 :key =" collection.id"
35- @click =" saveToCollection (collection)"
33+ @click =" toggleSavingToCollection (collection)"
3634 >
3735 <q-item-section avatar style =" min-width : auto " >
38- <q-icon class =" text-grey" name =" star_outline" />
36+ <q-icon
37+ :class =" savedToCollection(collection) ? 'text-primary' : 'text-grey'"
38+ :name =" savedToCollection(collection) ? 'star' : 'star_outline'"
39+ />
3940 </q-item-section >
4041 <q-item-section >{{ collection.title }}</q-item-section >
42+ <q-item-section v-if =" savedToCollection(collection)" side >
43+ <q-badge color =" primary" >&check ; Saved</q-badge >
44+ </q-item-section >
4145 </q-item >
4246 </q-list >
43-
4447 </div >
4548 </q-dialog >
4649</template >
@@ -60,14 +63,35 @@ export default {
6063 saveToReadLater () {
6164 console .log (` Save entry #${ this .entry .id } to read later` )
6265 },
63- saveToCollection (collection ) {
64- console .log (` Save entry #${ this .entry .id } to collection #${ collection .id } ` )
66+ toggleSavingToCollection (collection ) {
67+ const payload = { collectionId: collection .id , entryId: this .entry .id }
68+ const isSelectedCollection = this .$route .name === ' collection-entries'
69+ && + this .$route .params .collectionId === collection .id
70+
71+ if (this .savedToCollection (collection)) {
72+ // todo: Bug! Removing from collection not synced with UI
73+ this .$store .dispatch (' removeEntryFromCollection' , payload)
74+ if (isSelectedCollection) {
75+ this .$store .commit (' removeEntries' , [this .entry ])
76+ }
77+ } else {
78+ this .$store .dispatch (' saveEntryToCollection' , payload)
79+ if (isSelectedCollection) {
80+ this .$store .commit (' unshiftEntries' , [this .entry ])
81+ }
82+ }
6583 },
6684 },
6785 computed: {
6886 collections () {
6987 return this .$store .state .collections
7088 },
89+ savedToCollection () {
90+ console .log (this .entry )
91+ return collection => this .entry .collections .some (
92+ entryCollection => entryCollection .id === collection .id
93+ )
94+ },
7195 },
7296}
7397 </script >
0 commit comments