Home finished

This commit is contained in:
2026-01-20 12:08:36 +01:00
parent 2751b4181d
commit 1ab403b3b3
5 changed files with 84 additions and 17 deletions

View File

@@ -1,5 +1,4 @@
@page "/favorites"
@rendermode InteractiveServer
<PageTitle>Favorites</PageTitle>
@@ -15,8 +14,5 @@
{
var movies = await OmdbService.FetchMovies("Matrix");
var movieDetail = await OmdbService.FetchMovieDetail("tt11749868");
await JSRuntime.InvokeVoidAsync("console.log", movies);
await JSRuntime.InvokeVoidAsync("console.log", movieDetail);
}
}

View File

@@ -2,6 +2,54 @@
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
<form class="mb-3" @onsubmit="OnSearch">
<input type="text" class="form-control" placeholder="Search for movies..."
style="width: 40%; margin-bottom: 10px;"
@bind="searchTitle" @bind:event="oninput" />
<div class="d-flex align-items-center gap-2">
<button class="btn btn-primary" type="submit">Search</button>
<p class="mb-0">@((movies == null) ? "" : movies.TotalResults + " results found")</p>
</div>
</form>
Welcome to your new app.
<table class="table table-striped" id="moviesTable">
<thead class="table-primary">
<tr>
<th></th>
<th style="width: 100%;">Title</th>
<th>Year</th>
</tr>
</thead>
<tbody>
@if (movies?.Search != null)
{
@foreach (var movie in movies.Search)
{
<tr>
<td><button class="btn btn-secondary" @onclick="() => OnMovieSelected(movie.IdIMDB)">Details</button></td>
<td>@movie.Title</td>
<td>@movie.Year</td>
</tr>
}
}
</tbody>
</table>
@inject OmdbService OmdbService
@inject NavigationManager NavigationManager
@code {
private string searchTitle = "";
private MovieSearch? movies = null;
private async Task OnMovieSelected(string imdbID)
{
NavigationManager.NavigateTo($"/movie/{imdbID}");
}
private async Task OnSearch()
{
movies = await OmdbService.FetchMovies(searchTitle);
}
}

View File

@@ -0,0 +1,11 @@
@page "/movie/{id}"
<PageTitle>Movie Details</PageTitle>
<h1>TODO</h1>
<p>Movie ID: @id</p>
@code {
[Parameter]
public string id { get; set; }
}

View File

@@ -1,4 +1,5 @@
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
@rendermode InteractiveServer
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />