Projet-Symfony/templates/favorite/index.html.twig
2024-02-22 15:59:40 +01:00

49 lines
1.4 KiB
Twig

{% extends 'base.html.twig' %}
{% block title %}Favorites!{% endblock %}
{% block body %}
<script>
function rmFromFavs(id) {
// alert(id);
// /favorite/add/{id}
fetch("/favorite/remove/" + id).then((data) => {
if (data.status == 200) {
document.querySelector("#id" + id).classList.remove("fav");
alert("Removed from favs");
}
});
}
</script>
<main id="favorites">
<div class="results">
{% for album_liked in favorites %}
{% set main_artist = album_liked["artists_sort"] %}
{% set artists = album_liked["artists"] %}
{% set album = album_liked["title"] %}
<section class="album fav">
<span>
<h2>{{album}}</h2>
by
{% for artist in artists %}
<h3>{{artist["name"]}}</h3>
{% endfor %}
</span>
<img
loading="lazy"
src="{{album_liked['images'][0]["uri"]}}"
alt="{{album ~ ' by ' ~ main_artist}}"
/>
<h4>TrackList</h4>
{% for track in album_liked["tracklist"] %}
<p>{{track["title"]}} - {{track["duration"]}}</p>
{% endfor %}
<button onclick="rmFromFavs({{album_liked['id']}})">
Remove from favorites
</button>
</section>
{% endfor %}
</div>
</main>
{% endblock %}