ui(manager): improve search bindings
This commit is contained in:
38
ModpackUpdater.Apps.Manager/Ui/Models/DynamicDataView.cs
Normal file
38
ModpackUpdater.Apps.Manager/Ui/Models/DynamicDataView.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
||||
|
||||
public class DynamicDataView<T> : INotifyPropertyChanged where T : notnull
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
private string? searchText;
|
||||
private readonly Subject<string?> searchTextSubject = new();
|
||||
|
||||
public SourceList<T> List { get; } = new();
|
||||
public ReadOnlyObservableCollection<T> View { get; }
|
||||
|
||||
public DynamicDataView(Func<string?, Func<T, bool>> predicate)
|
||||
{
|
||||
List.Connect()
|
||||
.Filter(searchTextSubject/*.Throttle(TimeSpan.FromMilliseconds(250))*/.Select(predicate))
|
||||
.Bind(out var view)
|
||||
.Subscribe();
|
||||
searchTextSubject?.OnNext(searchText);
|
||||
View = view;
|
||||
}
|
||||
|
||||
public string? SearchText
|
||||
{
|
||||
get => searchText;
|
||||
set
|
||||
{
|
||||
searchText = value;
|
||||
searchTextSubject.OnNext(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user