Skip to content

Commit

Permalink
fix: correct handling of router links in profile for selected favorit…
Browse files Browse the repository at this point in the history
…es and removeFavorite operations.
  • Loading branch information
imprvhub committed May 8, 2024
1 parent 6d4a9ac commit e29f415
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
26 changes: 20 additions & 6 deletions components/Hero.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
:alt="name">
</div>
</div>

<div :class="$style.pane">
<transition
appear
Expand Down Expand Up @@ -104,7 +103,7 @@
/>
</svg>
</span>
<span class="txt">Add To Favorites</span>
<span class="txt">{{ isFavorite ? 'Remove from Favorites' : 'Add to Favorites' }}</span>
</button>

</div>
Expand All @@ -121,7 +120,7 @@
</template>
<script>
import supabase from '@/services/supabase';
import { name, stars, yearStart, cert, backdrop, poster, trailer } from '~/mixins/Details';
import { name, stars, yearStart, cert, backdrop, poster, trailer, id } from '~/mixins/Details';
import Modal from '~/components/Modal';
export default {
Expand All @@ -137,6 +136,7 @@ export default {
poster,
backdrop,
trailer,
id,
],
props: {
Expand All @@ -153,10 +153,12 @@ export default {
isFavorite: false,
hasAccessToken: false,
nameForDb: null,
starsForDb: null,
posterForDb: null,
yearStartForDb: null,
idForDb: null,
};
},
Expand All @@ -183,6 +185,7 @@ export default {
this.nameForDb = this.name;
this.starsForDb = this.stars;
this.yearStartForDb = this.yearStart;
this.idForDb = this.id;
},
methods: {
Expand Down Expand Up @@ -236,6 +239,7 @@ export default {
}
},
openModal() {
this.modalVisible = true;
},
Expand Down Expand Up @@ -298,16 +302,22 @@ export default {
}
},
removeFavorite(favoritesJson, favId) {
const updatedFavorites = { ...favoritesJson };
for (const key in updatedFavorites) {
updatedFavorites[key] = updatedFavorites[key].filter(id => String(id) !== favId && !String(id).endsWith(favId));
if (Array.isArray(updatedFavorites[key])) {
updatedFavorites[key] = updatedFavorites[key].filter(item => {
if (typeof item === 'object') {
return Object.keys(item)[0] !== favId;
} else {
return item !== favId;
}
});
}
}
return updatedFavorites;
},
addFavorite(favoritesJson, favId) {
const { type, id } = this.parseFavId(favId);
const category = type === 'movie' ? 'movies' : 'tv';
Expand Down Expand Up @@ -345,6 +355,7 @@ export default {
starsForDb: this.starsForDb,
yearStartForDb: this.yearStartForDb,
posterForDb: this.posterForDb,
idForDb: this.id,
}
}
};
Expand All @@ -356,6 +367,7 @@ export default {
starsForDb: this.starsForDb,
yearStartForDb: this.yearStartForDb,
posterForDb: this.posterForDb,
idForDb: this.id,
};
} else {
favoritesJson[category][index].push({
Expand All @@ -365,6 +377,7 @@ export default {
starsForDb: this.starsForDb,
yearStartForDb: this.yearStartForDb,
posterForDb: this.posterForDb,
idForDb: this.id,
}
}
});
Expand All @@ -378,6 +391,7 @@ export default {
starsForDb: this.starsForDb,
yearStartForDb: this.yearStartForDb,
posterForDb: this.posterForDb,
idForDb: this.id,
}
}
});
Expand Down
8 changes: 8 additions & 0 deletions mixins/Details.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { apiImgUrl } from '~/api';

export const id = {
computed: {
id () {
return this.item.id;
}
}

}

export const name = {
computed: {
Expand Down
12 changes: 6 additions & 6 deletions pages/profile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<br>
<div v-if="moviesFetched.length > 0 || tvFetched.length > 0">
<div class="column">
<h2>Películas Favoritas</h2>
<h2 v-if="moviesFetched.length > 0" class="text-white text-center">Favorite Movies</h2>
<div class="movie-grid">
<div v-for="(movie, index) in moviesFetched" :key="index" class="movie-card">
<a :href="'https://sonarflix.netlify.app/' + movieKey">
<a :href="'https://sonarflix.netlify.app/movie/' + movie.details.idForDb">
<img :src="movie.details.posterForDb" alt="Movie Poster" class="poster" />
</a>
<p>{{ movie.details.nameForDb }}</p>
Expand All @@ -20,10 +20,10 @@
</div>
<br>
<div class="column">
<h2>Programas de TV Favoritos</h2>
<h2 v-if="tvFetched.length > 0" class="text-white text-center">Favorite TV Shows</h2>
<div class="tv-show-grid">
<div v-for="(tvShow, index) in tvFetched" :key="index" class="tv-show-card">
<a :href="'https://sonarflix.netlify.app/' + tvKey">
<a :href="'https://sonarflix.netlify.app/tv/' + tvShow.details.idForDb">
<img :src="tvShow.details.posterForDb" alt="TV Show Poster" class="poster" />
</a>
<p>{{ tvShow.details.nameForDb }}</p>
Expand All @@ -34,12 +34,12 @@
</div>
</div>
<div v-else>
<p>No hay favoritos o lista agregada hasta el momento.</p>
<p>No favorites or list added yet.</p>
</div>
<br>
<div class="button-container">
<button class="button button--icon" @click="signOut">
<span class="txt">Cerrar sesión</span>
<span class="txt">Log out</span>
</button>
</div>
</section>
Expand Down

0 comments on commit e29f415

Please sign in to comment.