From 3229bdfb9176bb8482d8bb670d91d9e21292ac29 Mon Sep 17 00:00:00 2001 From: ZeKap Date: Thu, 22 Feb 2024 16:20:18 +0100 Subject: [PATCH] dynamic add and remove to favs thanks to css --- assets/styles/app.css | 16 ++++++++++++++++ templates/favorite/index.html.twig | 5 +++-- templates/search/search.html.twig | 8 ++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/assets/styles/app.css b/assets/styles/app.css index 295288f..842e444 100644 --- a/assets/styles/app.css +++ b/assets/styles/app.css @@ -155,6 +155,10 @@ main:is(#searchResults, #favorites) { } } +main#favorites > div.results > :not(section.fav) { + display: none; +} + section.album { display: flex; flex-direction: column; @@ -167,8 +171,20 @@ section.album { transition: all ease-out 0.15s; box-shadow: var(--shadow); border-radius: var(--radius); + & > button.toFav { + display: block; + } + & > p.alreadyFav { + display: none; + } &.fav { transform: rotate(-1deg); + & > p.alreadyFav { + display: block; + } + & > button.toFav { + display: none; + } } &:hover { transform: scale(1.01); diff --git a/templates/favorite/index.html.twig b/templates/favorite/index.html.twig index 9659a1e..b7d33f4 100644 --- a/templates/favorite/index.html.twig +++ b/templates/favorite/index.html.twig @@ -10,7 +10,6 @@ fetch("/favorite/remove/" + id).then((data) => { if (data.status == 200) { document.querySelector("#id" + id).classList.remove("fav"); - alert("Removed from favs"); } }); } @@ -21,8 +20,10 @@ {% set main_artist = album_liked["artists_sort"] %} {% set artists = album_liked["artists"] %} {% set album = album_liked["title"] %} -
+ {% set fruit = album_liked["fruit"] %} +
+

{{fruit}}

{{album}}

by {% for artist in artists %} diff --git a/templates/search/search.html.twig b/templates/search/search.html.twig index 8c5b5df..f7b47ff 100644 --- a/templates/search/search.html.twig +++ b/templates/search/search.html.twig @@ -7,7 +7,6 @@ endblock %} {% block body %} fetch("/favorite/add/" + id).then((data) => { if (data.status == 200) { document.querySelector("#id" + id).classList.add("fav"); - alert("Added to favs"); } }); } @@ -31,16 +30,13 @@ endblock %} {% block body %} src="{{result['cover_image']}}" alt="{{album ~ ' by ' ~ artist}}" /> - {% if result['isLiked'] == 'true' %} -

+

Already fav, go to favorites

- {% else %} - - {% endif %}
{% endfor %}