Merge branch 'main' of gitpro:ThomasRubini/ProjetSymfony

This commit is contained in:
Djalim Simaila 2024-02-22 15:20:25 +00:00
commit b3e8ec540a
4 changed files with 39 additions and 25 deletions

View File

@ -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);

View File

@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManagerInterface;
Use App\Utils;
use App\Utils;
class SearchController extends AbstractController
{
@ -37,7 +37,8 @@ class SearchController extends AbstractController
}
}
private static function getEmojiName(string | null $emoji) : string | null {
private static function getEmojiName(string | null $emoji): string | null
{
return match ($emoji) {
"🍎" => "apple",
"🍐" => "pear",
@ -66,14 +67,14 @@ class SearchController extends AbstractController
$fruit = $request->query->get('fruit');
$user_query = $request->query->get('q');
$fruit_emoji = SearchController::getEmojiName($fruit);
if ($fruit_emoji == null) {
$fruit_name = SearchController::getEmojiName($fruit);
if ($fruit_name == null) {
// We do not support requests without a fruit or with an invalid one
// Redirect to the homepage in this case
return $this->redirect('/');
}
$fruit_query = $user_query . " " . $fruit_emoji;
$fruit_query = $user_query . " " . $fruit_name;
$page_str = strval($page);
$response = Utils::makeRequest("GET", "/database/search", [
"q" => $fruit_query,
@ -109,7 +110,7 @@ class SearchController extends AbstractController
return $this->render('search/search.html.twig', [
'controller_name' => 'SearchController',
'query' => $user_query,
'fruit_emoji' => $fruit_emoji,
'fruit_emoji' => $fruit,
'fruit_name' => SearchController::getEmojiName($fruit),
'page' => $page,
'all_page' => $response["pagination"]["pages"],

View File

@ -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"] %}
<section class="album fav">
{% set fruit = album_liked["fruit"] %}
<section class="album fav" id="id{{album_liked['id']}}">
<span>
<h1>{{fruit}}</h1>
<h2>{{album}}</h2>
by
{% for artist in artists %}

View File

@ -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' %}
<p>
<p class="alreadyFav">
<b>Already fav</b>, go to
<a href="{{url('app_favorite')}}">favorites</a>
</p>
{% else %}
<button onclick="addToFavs({{result['id']}})">
<button class="toFav" onclick="addToFavs({{result['id']}})">
Add to favorites
</button>
{% endif %}
</section>
{% endfor %}
</div>