dynamic add and remove to favs thanks to css

This commit is contained in:
ZeKap 2024-02-22 16:20:18 +01:00
parent ad85898786
commit 3229bdfb91
No known key found for this signature in database
GPG Key ID: 8D70E0631DD5792A
3 changed files with 21 additions and 8 deletions

View File

@ -155,6 +155,10 @@ main:is(#searchResults, #favorites) {
} }
} }
main#favorites > div.results > :not(section.fav) {
display: none;
}
section.album { section.album {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -167,8 +171,20 @@ section.album {
transition: all ease-out 0.15s; transition: all ease-out 0.15s;
box-shadow: var(--shadow); box-shadow: var(--shadow);
border-radius: var(--radius); border-radius: var(--radius);
& > button.toFav {
display: block;
}
& > p.alreadyFav {
display: none;
}
&.fav { &.fav {
transform: rotate(-1deg); transform: rotate(-1deg);
& > p.alreadyFav {
display: block;
}
& > button.toFav {
display: none;
}
} }
&:hover { &:hover {
transform: scale(1.01); transform: scale(1.01);

View File

@ -10,7 +10,6 @@
fetch("/favorite/remove/" + id).then((data) => { fetch("/favorite/remove/" + id).then((data) => {
if (data.status == 200) { if (data.status == 200) {
document.querySelector("#id" + id).classList.remove("fav"); document.querySelector("#id" + id).classList.remove("fav");
alert("Removed from favs");
} }
}); });
} }
@ -21,8 +20,10 @@
{% set main_artist = album_liked["artists_sort"] %} {% set main_artist = album_liked["artists_sort"] %}
{% set artists = album_liked["artists"] %} {% set artists = album_liked["artists"] %}
{% set album = album_liked["title"] %} {% set album = album_liked["title"] %}
<section class="album fav"> {% set fruit = album_liked["fruit"] %}
<section class="album fav" id="id{{album_liked['id']}}">
<span> <span>
<h1>{{fruit}}</h1>
<h2>{{album}}</h2> <h2>{{album}}</h2>
by by
{% for artist in artists %} {% for artist in artists %}

View File

@ -7,7 +7,6 @@ endblock %} {% block body %}
fetch("/favorite/add/" + id).then((data) => { fetch("/favorite/add/" + id).then((data) => {
if (data.status == 200) { if (data.status == 200) {
document.querySelector("#id" + id).classList.add("fav"); document.querySelector("#id" + id).classList.add("fav");
alert("Added to favs");
} }
}); });
} }
@ -31,16 +30,13 @@ endblock %} {% block body %}
src="{{result['cover_image']}}" src="{{result['cover_image']}}"
alt="{{album ~ ' by ' ~ artist}}" alt="{{album ~ ' by ' ~ artist}}"
/> />
{% if result['isLiked'] == 'true' %} <p class="alreadyFav">
<p>
<b>Already fav</b>, go to <b>Already fav</b>, go to
<a href="{{url('app_favorite')}}">favorites</a> <a href="{{url('app_favorite')}}">favorites</a>
</p> </p>
{% else %} <button class="toFav" onclick="addToFavs({{result['id']}})">
<button onclick="addToFavs({{result['id']}})">
Add to favorites Add to favorites
</button> </button>
{% endif %}
</section> </section>
{% endfor %} {% endfor %}
</div> </div>