Files
Chronos/src/Titano.App/Sections/LibraryView.xaml.cs
T
Claude f4579ef64c fix(app): scroll to a timeline month once and stop at the end of the list
A month chosen on the timeline scrolled the grid on every later page load;
it now scrolls once, gives up when no page is left (or only server cards
show), and saved views notice the search text once its delay has passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 16:29:01 +00:00

66 lines
2.5 KiB
C#

using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Threading;
using Titano.App.Library;
using Titano.Ui.Visuals;
namespace Titano.App.Sections;
public partial class LibraryView : UserControl
{
public LibraryView()
{
InitializeComponent();
DataContextChanged += OnDataContextChanged;
}
private LibraryViewModel? Model => DataContext as LibraryViewModel;
/// <summary>Loads the next page when the grid or the list scrolls within two screens of its end.</summary>
private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
{
if (Model is not { } vm || e.ExtentHeight <= 0) return;
if (e.VerticalOffset + e.ViewportHeight >= e.ExtentHeight - 2 * Math.Max(e.ViewportHeight, 200)) _ = vm.LoadMoreAsync();
}
/// <summary>A month of the timeline: the Library narrows to its year and the grid scrolls to it.</summary>
private void OnSlotActivated(object sender, ChartItemEventArgs e) => Model?.ShowSlot(e.Row, e.Column);
/// <summary>"Saved views" and "Rate ▾" open their menu under themselves.</summary>
private void OnOpenMenu(object sender, RoutedEventArgs e)
{
if (sender is not Button { ContextMenu: { } menu } button) return;
menu.DataContext = DataContext;
menu.PlacementTarget = button;
menu.Placement = PlacementMode.Bottom;
menu.IsOpen = true;
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is LibraryViewModel old)
{
old.ScrollRequested -= OnScrollRequested;
old.PropertyChanged -= OnModelChanged;
}
if (e.NewValue is LibraryViewModel model)
{
model.ScrollRequested += OnScrollRequested;
model.PropertyChanged += OnModelChanged;
}
}
private void OnScrollRequested(SequenceItem item) =>
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () => CardGrid.ScrollIntoView(item));
/// <summary>A dialog that opens takes the keyboard: its first field or button.</summary>
private void OnModelChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != nameof(LibraryViewModel.Dialog) || Model?.Dialog is null || !IsVisible) return;
Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
}
}