From e4c6861c061b3fb97623aa30ff34116e4b5f9606 Mon Sep 17 00:00:00 2001
From: Alexis <35.alexis.pele@gmail.com>
Date: Fri, 19 Mar 2021 23:03:54 +0100
Subject: [PATCH] Added store favourites
---
src/components/celestials/CelestialCard.vue | 72 +++++++++++++++++++--
src/store/index.ts | 9 ++-
src/views/celestials/Celestial.vue | 10 ---
3 files changed, 72 insertions(+), 19 deletions(-)
diff --git a/src/components/celestials/CelestialCard.vue b/src/components/celestials/CelestialCard.vue
index 4d61454..84e7d12 100644
--- a/src/components/celestials/CelestialCard.vue
+++ b/src/components/celestials/CelestialCard.vue
@@ -42,6 +42,15 @@
+
-
- Détails
-
+ favorite
+
@@ -89,6 +99,8 @@
@@ -121,8 +147,18 @@ export default defineComponent({
.card-icon {
display: block;
position: absolute;
- top: 0;
+ top: 20px;
+ bottom: 20px;
+ left: 0;
right: 0;
+ user-select: none;
+ pointer-events: none;
+ opacity: 4%;
+ img {
+ height: 100%;
+ width: 100%;
+ z-index: -1;
+ }
}
> * {
@@ -135,6 +171,30 @@ export default defineComponent({
flex: 1 1 auto;
min-height: 30px;
}
+
+ .card-info {
+ position: absolute;
+ top: 0;
+ right: 0;
+ }
+
+ .card-actions {
+ color: #afafaf;
+ .favourite {
+ .icon {
+ color: #afafaf;
+ }
+ &.active {
+ .icon {
+ position: relative;
+ display: inline-block;
+ will-change: font-size;
+ animation: toggleFavHeart 0.6s cubic-bezier(0.17, 0.89, 0.32, 1.49);
+ animation-fill-mode: forwards;
+ }
+ }
+ }
+ }
}
}
diff --git a/src/store/index.ts b/src/store/index.ts
index 765e2f0..82f088d 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -3,6 +3,7 @@ import { createStore } from "vuex";
export default createStore({
state: () => ({
user: {
+ avatarUrl: "",
favourites: Array<{ id: string }>()
}
}),
@@ -12,7 +13,7 @@ export default createStore({
return state.user.favourites.length;
},
// Returns true if celestial is fav
- isAlreadyFav: state => (celestialId: string) => {
+ isFav: state => (celestialId: string) => {
return state.user.favourites.find(fav => fav.id === celestialId);
}
},
@@ -21,13 +22,15 @@ export default createStore({
state.user.favourites.push({ id: celestialId });
},
removeFav: (state, celestialId: string) => {
- state.user.favourites = state.user.favourites.filter(fav => fav.id != celestialId);
+ state.user.favourites = state.user.favourites.filter(
+ fav => fav.id != celestialId
+ );
}
},
actions: {
toggleFav: ({ commit, getters }, celestialId: string) => {
// If the celestial is not faved
- if (!getters.isAlreadyFav(celestialId)) {
+ if (!getters.isFav(celestialId)) {
// ... favs it
commit("addFav", celestialId);
} else {
diff --git a/src/views/celestials/Celestial.vue b/src/views/celestials/Celestial.vue
index 50cb7cc..02c8dda 100644
--- a/src/views/celestials/Celestial.vue
+++ b/src/views/celestials/Celestial.vue
@@ -8,7 +8,6 @@