chore: add listener for favorite changes
This commit is contained in:
@@ -194,6 +194,19 @@
|
|||||||
set: (id, val) => localStorage.setItem(id, JSON.stringify(val)),
|
set: (id, val) => localStorage.setItem(id, JSON.stringify(val)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// listeners
|
||||||
|
emitter.on('favorite', ({ id, isFav }) => {
|
||||||
|
const favs = store.get('favorites') || [];
|
||||||
|
const idx = favs.indexOf(id);
|
||||||
|
|
||||||
|
// remove previously favorited strain
|
||||||
|
if (idx >= 0 && !isFav) {
|
||||||
|
store.set('favorites', favs.filter(f => f !== id));
|
||||||
|
} else if (idx === -1 && isFav) {
|
||||||
|
store.set('favorites', favs.concat(id));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// vue helpers
|
// vue helpers
|
||||||
Vue.filter('capitalize', value => {
|
Vue.filter('capitalize', value => {
|
||||||
if (!value) return '';
|
if (!value) return '';
|
||||||
|
|||||||
Reference in New Issue
Block a user