ui(manager): improve search bindings

This commit is contained in:
2025-11-18 16:21:34 +01:00
parent 86f93cf3d7
commit 2cbe25e0f8
12 changed files with 89 additions and 52 deletions

View File

@@ -1,5 +1,6 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using DynamicData;
using ModpackUpdater.Apps.Manager.Api.Model;
using ModpackUpdater.Apps.Manager.Ui.Models.UpdatesCollectorViewMode;
using ModpackUpdater.Manager;
@@ -36,7 +37,7 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase
if (updates == null || updates.Length == 0 || updates[0].Tag == action.SourceTag)
continue;
Model.Updates.Add(new(updates, action));
Model.Updates.List.Add(new(updates, action));
if (IsClosed)
break;
@@ -47,7 +48,7 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase
protected override object GetResult()
{
return new ModUpdates(Model.Updates);
return new ModUpdates([.. Model.Updates.List.Items]);
}
private async void Me_OnLoaded(object? sender, RoutedEventArgs e)
@@ -55,18 +56,9 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase
await FindUpdates();
}
private void TextBoxSearch_OnTextChanged(object? sender, TextChangedEventArgs e)
{
var searchString = Model.SearchText?.Trim().ToLowerInvariant();
var hasNoSearch = string.IsNullOrWhiteSpace(searchString);
foreach (var item in Model.Updates)
item.Visible = hasNoSearch || (item.Origin.Name != null && item.Origin.Name.Contains(searchString!, StringComparison.InvariantCultureIgnoreCase));
}
private void ButtonRemoveUpdate_Click(object? sender, RoutedEventArgs e)
{
if (sender is Button button && button.DataContext is ModUpdateInfo update)
Model.Updates.Remove(update);
Model.Updates.List.Remove(update);
}
}