Aggiungi gestione dei film preferiti e integrazione con Blazored.LocalStorage

This commit is contained in:
2026-01-20 14:24:09 +01:00
parent 86b91263a8
commit 40abf65d06
5 changed files with 113 additions and 2 deletions

View File

@@ -2,7 +2,26 @@
<PageTitle>Movie Details</PageTitle>
<div style="display: grid; grid-template-columns: 1fr 2fr; grid-template-rows: auto auto; gap: 20px; max-width: 800px; margin-right: auto;">
<style>
.my-grid {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: auto auto;
gap: 20px;
max-width: 800px;
margin-right: auto;
}
.favorite {
background-color: gold;
color: black;
}
.not-favorite {
background-color: gray;
color: white;
}
</style>
<div class="my-grid">
@if (movie is not null)
{
<h1>@movie.Title</h1>
@@ -11,7 +30,14 @@
<div class="details">
<p>@movie.Runtime</p>
<p>@movie.Plot</p>
<button>Favorite</button>
@if(ManageFavorite.IsFavorite(id))
{
<button class="btn-secondary favorite" @onclick="ToggleFavoriteMovie">Remove Favorite</button>
}
else
{
<button class="btn-secondary not-favorite" @onclick="ToggleFavoriteMovie">Add to Favorites</button>
}
</div>
}
else
@@ -22,6 +48,7 @@
@inject OmdbService OmdbService
@inject ManageFavorite ManageFavorite
@code {
[Parameter]
@@ -32,4 +59,18 @@
{
movie = await OmdbService.FetchMovieDetail(id);
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await ManageFavorite.LoadFavorites();
StateHasChanged();
}
}
private async Task ToggleFavoriteMovie()
{
await ManageFavorite.ToggleFavoriteMovie(id);
}
}