From 7de11a53402d03daab0dfdbdcfb26b7409b64b91 Mon Sep 17 00:00:00 2001 From: Mike McGhen Date: Sat, 23 Aug 2025 12:45:14 -0400 Subject: [PATCH] Initial overhaul of Movie Search --- .../Components/Pages/Counter.razor | 19 - .../Components/Pages/SearchShows.razor | 632 +++++++++++++++--- .../Components/Pages/Weather.razor | 64 -- 3 files changed, 546 insertions(+), 169 deletions(-) delete mode 100644 MovieActorLookup/Components/Pages/Counter.razor delete mode 100644 MovieActorLookup/Components/Pages/Weather.razor diff --git a/MovieActorLookup/Components/Pages/Counter.razor b/MovieActorLookup/Components/Pages/Counter.razor deleted file mode 100644 index 1a4f8e7..0000000 --- a/MovieActorLookup/Components/Pages/Counter.razor +++ /dev/null @@ -1,19 +0,0 @@ -@page "/counter" -@rendermode InteractiveServer - -Counter - -

Counter

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/MovieActorLookup/Components/Pages/SearchShows.razor b/MovieActorLookup/Components/Pages/SearchShows.razor index 1b42a43..a4c943d 100644 --- a/MovieActorLookup/Components/Pages/SearchShows.razor +++ b/MovieActorLookup/Components/Pages/SearchShows.razor @@ -3,128 +3,588 @@ @inject ShowService ShowService @rendermode InteractiveServer -

Search for Actor by TV Show and Character Name

+
+
+

Discover Actors & Their Shows

+

Search by TV show and character to explore an actor's complete filmography

+
-
- - - -
- -@if (_isSearching) -{ -

Searching...

-} -else if (_actor != null) -{ -

Actor: @_actor.Name

- - @if (_matchedShow != null) - { -
- Show Poster -
-
@_matchedShow.ShowTitle
- @_matchedShow.CharacterName -
- First Air Date: @_matchedShow.FirstAirDate +
+
+
+ +
📺
+
+
+ +
🎭
- } - - @foreach (var group in _actor.TvCharacters - .GroupBy(tc => tc.Franchise) - .OrderBy(g => g.Key == "Standalone") - .ThenBy(g => g.Key)) - { -
- @foreach (var show in (group.Key == "Standalone" - ? group.OrderByDescending(tc => DateTime.TryParse(tc.FirstAirDate, out var d) ? d : DateTime.MinValue) - : group.OrderBy(tc => DateTime.TryParse(tc.FirstAirDate, out var d) ? d : DateTime.MaxValue))) + +
+ + @if (_isSearching) + { +
+
+
+
+
+
+

Finding the perfect match...

+
+ } + else if (_actor != null) + { +
+
+

@_actor.Name

+
@_actor.TvCharacters.Count show@(_actor.TvCharacters.Count != 1 ? "s" : "") found
+
+ + @if (_matchedShow != null) + { +
+

Your Search Match

+
} + +
+

Complete TV Filmography

+ + @foreach (var group in _actor.TvCharacters + .GroupBy(tc => tc.Franchise) + .OrderBy(g => g.Key == "Standalone") + .ThenBy(g => g.Key)) + { + @if (group.Key != "Standalone") + { +
+
@group.Key Series
+
+ } + +
+ @foreach (var show in (group.Key == "Standalone" + ? group.OrderByDescending(tc => DateTime.TryParse(tc.FirstAirDate, out var d) ? d : DateTime.MinValue) + : group.OrderBy(tc => DateTime.TryParse(tc.FirstAirDate, out var d) ? d : DateTime.MaxValue))) + { +
+
+ @show.ShowTitle Poster +
+
+
@show.ShowTitle
+
as @show.CharacterName
+ @if (!string.IsNullOrEmpty(show.Overview)) + { +

@(show.Overview.Length > 120 ? show.Overview.Substring(0, 120) + "..." : show.Overview)

+ } +
@show.FirstAirDate
+
+
+ } +
+ } +
} -} -else -{ -

Enter a TV show title and character name to begin your search.

-} + else if (!string.IsNullOrEmpty(_tvTitle) || !string.IsNullOrEmpty(_characterName)) + { +
+
🔍
+

No matches found

+

Try adjusting your search terms or check the spelling

+
+ } + else + { +
+
🎬
+

Ready to explore?

+

Enter a TV show title and character name to discover an actor's complete television journey

+
+ } +
+ + @code { - private string _tvTitle; - private string _characterName; + private string _tvTitle = ""; + private string _characterName = ""; private Actor _actor; private TvCharacter _matchedShow; private bool _isSearching = false; private async Task SearchForActorAndCharacters() { + if (string.IsNullOrWhiteSpace(_tvTitle) || string.IsNullOrWhiteSpace(_characterName)) + return; + _isSearching = true; _actor = null; _matchedShow = null; StateHasChanged(); - if (!string.IsNullOrWhiteSpace(_tvTitle) && !string.IsNullOrWhiteSpace(_characterName)) + try { var shows = await ShowService.GetShowsByTitle(_tvTitle); + foreach (var show in shows) { var credits = await ShowService.GetShowCreditsById(show.Id); + foreach (var cast in credits.Cast) { - if (cast.Character.ToLower().Contains(_characterName.ToLower())) + if (cast.Character.Contains(_characterName, StringComparison.OrdinalIgnoreCase)) { if (_actor == null) { _actor = new Actor(cast.Name); - int personId = cast.Id; - - var filmography = await ShowService.GetActorTvCreditsById(personId); - if (filmography?.Cast != null) - { - foreach (var role in filmography.Cast) - { - var fullShow = await ShowService.GetShowDetailsById(role.Id); - - var tvCharacter = new TvCharacter - { - ShowTitle = role.ShowTitle, - CharacterName = role.Character, - ShowPosterPath = role.PosterPath, - FirstAirDate = DateTime.TryParse(fullShow?.FirstAirDate, out var parsedDate) - ? parsedDate.ToString("MM/dd/yyyy") - : "N/A", - Overview = fullShow?.Overview ?? "", - Franchise = fullShow?.BelongsToCollection?.Name ?? "Standalone" - }; - - _actor.TvCharacters.Add(tvCharacter); - - if (_matchedShow == null && - role.ShowTitle == show.Name && - role.Character == cast.Character) - { - _matchedShow = tvCharacter; - } - } - } + await LoadActorFilmography(cast.Id, (object)show, (object)cast); } + break; } } + + if (_actor != null) break; + } + } + catch (Exception ex) + { + Console.WriteLine($"Search error: {ex.Message}"); + } + finally + { + _isSearching = false; + StateHasChanged(); + } + } + + private async Task LoadActorFilmography(int personId, object originalShow, object originalCast) + { + var filmography = await ShowService.GetActorTvCreditsById(personId); + + if (filmography?.Cast != null) + { + foreach (var role in filmography.Cast) + { + var fullShow = await ShowService.GetShowDetailsById(role.Id); + + var tvCharacter = new TvCharacter + { + ShowTitle = role.ShowTitle ?? "Unknown Title", + CharacterName = role.Character ?? "Unknown Character", + ShowPosterPath = role.PosterPath ?? "", + FirstAirDate = DateTime.TryParse(fullShow?.FirstAirDate, out var parsedDate) + ? parsedDate.ToString("MMM dd, yyyy") + : "Unknown Date", + Overview = fullShow?.Overview ?? "", + Franchise = fullShow?.BelongsToCollection?.Name ?? "Standalone" + }; + + _actor.TvCharacters.Add(tvCharacter); + + if (_matchedShow == null && + string.Equals(role.ShowTitle, GetPropertyValue(originalShow, "Name")?.ToString(), StringComparison.OrdinalIgnoreCase) && + string.Equals(role.Character, GetPropertyValue(originalCast, "Character")?.ToString(), StringComparison.OrdinalIgnoreCase)) + { + _matchedShow = tvCharacter; + } } } - - _isSearching = false; - StateHasChanged(); } -} + + private object GetPropertyValue(object obj, string propertyName) + { + if (obj == null) return null; + var property = obj.GetType().GetProperty(propertyName); + return property?.GetValue(obj); + } +} \ No newline at end of file diff --git a/MovieActorLookup/Components/Pages/Weather.razor b/MovieActorLookup/Components/Pages/Weather.razor deleted file mode 100644 index 43a1ecb..0000000 --- a/MovieActorLookup/Components/Pages/Weather.razor +++ /dev/null @@ -1,64 +0,0 @@ -@page "/weather" -@attribute [StreamRendering] - -Weather - -

Weather

- -

This component demonstrates showing data.

- -@if (forecasts == null) -{ -

Loading...

-} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
-} - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - // Simulate asynchronous loading to demonstrate streaming rendering - await Task.Delay(500); - - var startDate = DateOnly.FromDateTime(DateTime.Now); - var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; - forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = summaries[Random.Shared.Next(summaries.Length)] - }).ToArray(); - } - - private class WeatherForecast - { - public DateOnly Date { get; set; } - public int TemperatureC { get; set; } - public string? Summary { get; set; } - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } -}