js and style add to fav

This commit is contained in:
ZeKap 2024-02-22 15:29:29 +01:00
parent c852caac35
commit d557c7e353
No known key found for this signature in database
GPG Key ID: 8D70E0631DD5792A
2 changed files with 43 additions and 6 deletions

View File

@ -141,6 +141,7 @@ main#searchResults {
text-align: center; text-align: center;
} }
& div.results { & div.results {
width: 90%;
display: grid; display: grid;
grid-template-columns: 1fr 1fr 1fr; grid-template-columns: 1fr 1fr 1fr;
justify-items: stretch; justify-items: stretch;
@ -152,10 +153,24 @@ section.album {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center;
gap: 0.6rem;
padding: 0.7rem; padding: 0.7rem;
width: auto; width: auto;
transition: all ease-out 0.2s; /* max-width: max-content; */
transition: all ease-out 0.15s;
box-shadow: var(--shadow); box-shadow: var(--shadow);
border-radius: var(--radius);
&.fav {
transform: rotate(-1deg);
}
&:hover {
transform: scale(1.01);
box-shadow: var(--shadow-hover);
&.fav {
transform: rotate(-1deg) scale(1.01);
}
}
& > span { & > span {
width: fit-content; width: fit-content;
& > * { & > * {
@ -167,8 +182,16 @@ section.album {
width: 100%; width: 100%;
max-width: 260px; max-width: 260px;
} }
&:hover { & > button {
transform: scale(1.02); background: var(--light);
box-shadow: var(--shadow-hover); border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 8px 12px;
transition: all ease-out 0.15s;
border: none;
outline: none;
&:hover {
box-shadow: var(--shadow-hover);
}
} }
} }

View File

@ -1,11 +1,23 @@
{% extends 'base.html.twig' %} {% block title %} results for {{ query }} !{% {% extends 'base.html.twig' %} {% block title %} results for {{ query }} !{%
endblock %} {% block body %} endblock %} {% block body %}
<script>
function addToFavs(id) {
// alert(id);
// /favorite/add/{id}
fetch("/favorite/add/" + id).then((data) => {
if (data.status == 200) {
document.querySelector("#id" + id).classList.add("fav");
alert("Added to favs");
}
});
}
</script>
<main id="searchResults"> <main id="searchResults">
<h1>Results for "{{ query }}" with {{fruit_emoji}}:</h1> <h1>Results for "{{ query }}" with {{fruit_emoji}}:</h1>
<div class="results"> <div class="results">
{% for result in results %} {% set array = result['title']|split('-') %} {% for result in results %} {% set array = result['title']|split('-') %}
{% set artist = array[0] %} {% set album = array[1] %} {% set artist = array[0] %} {% set album = array[1] %}
<section class="album"> <section class="album" id="id{{result['id']}}">
<span> <span>
<h2>{{album}}</h2> <h2>{{album}}</h2>
by by
@ -16,7 +28,9 @@ endblock %} {% block body %}
src="{{result['cover_image']}}" src="{{result['cover_image']}}"
alt="{{album ~ ' by ' ~ artist}}" alt="{{album ~ ' by ' ~ artist}}"
/> />
<br /> <button onclick="addToFavs({{result['id']}})">
Add to favorites
</button>
</section> </section>
{% endfor %} {% endfor %}
</div> </div>