diff --git a/Wabbajack.App.Wpf/ViewModels/Gallery/ModListGalleryVM.cs b/Wabbajack.App.Wpf/ViewModels/Gallery/ModListGalleryVM.cs index 48d78060..bdba2dff 100644 --- a/Wabbajack.App.Wpf/ViewModels/Gallery/ModListGalleryVM.cs +++ b/Wabbajack.App.Wpf/ViewModels/Gallery/ModListGalleryVM.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Input; using DynamicData; +using DynamicData.Binding; using Microsoft.Extensions.Logging; using ReactiveUI; using ReactiveUI.Fody.Helpers; @@ -91,6 +92,7 @@ namespace Wabbajack SettingsManager settingsManager, ModListDownloadMaintainer maintainer, CancellationToken cancellationToken) : base(logger) { + var searchThrottle = TimeSpan.FromSeconds(0.5); _wjClient = wjClient; _logger = logger; _locator = locator; @@ -124,7 +126,8 @@ namespace Wabbajack .DisposeWith(disposables); var searchTextPredicates = this.ObservableForProperty(vm => vm.Search) - .Select(change => change.Value) + .Throttle(searchThrottle, RxApp.MainThreadScheduler) + .Select(change => change.Value.Trim()) .StartWith(Search) .Select>(txt => { @@ -166,6 +169,12 @@ namespace Wabbajack }) .StartWith(_ => true); + var searchSorter = this.WhenValueChanged(x => x.Search) + .Where(x => !string.IsNullOrWhiteSpace(x)) + .Throttle(searchThrottle, RxApp.MainThreadScheduler) + .Select(s => SortExpressionComparer + .Descending(modlist => modlist.Metadata.Title.StartsWith(s, StringComparison.InvariantCultureIgnoreCase)) + .ThenByDescending(modlist => modlist.Metadata.Title.Contains(s, StringComparison.InvariantCultureIgnoreCase))); _modLists.Connect() .ObserveOn(RxApp.MainThreadScheduler) .Filter(searchTextPredicates) @@ -173,6 +182,8 @@ namespace Wabbajack .Filter(showUnofficial) .Filter(showNSFWFilter) .Filter(gameFilter) + .Sort(searchSorter) + .TreatMovesAsRemoveAdd() .Bind(out _filteredModLists) .Subscribe((_) => { diff --git a/Wabbajack.App.Wpf/Views/ModListGalleryView.xaml.cs b/Wabbajack.App.Wpf/Views/ModListGalleryView.xaml.cs index 187edc73..f8b36d7c 100644 --- a/Wabbajack.App.Wpf/Views/ModListGalleryView.xaml.cs +++ b/Wabbajack.App.Wpf/Views/ModListGalleryView.xaml.cs @@ -45,12 +45,16 @@ namespace Wabbajack .DisposeWith(dispose); - this.WhenAny(x => x.SearchBox.Text) - .Throttle(TimeSpan.FromSeconds(0.2), RxApp.TaskpoolScheduler) + /* + this.WhenAnyValue(x => x.ViewModel.Search) + .Throttle(TimeSpan.FromSeconds(0.25), RxApp.TaskpoolScheduler) .Select(x => x?.Trim()) - .BindToStrict(this, x => x.ViewModel.Search) + .BindToStrict(this, x => x.SearchBox.Text) .DisposeWith(dispose); + */ + this.BindStrict(ViewModel, vm => vm.Search, x => x.SearchBox.Text) + .DisposeWith(dispose); this.BindStrict(ViewModel, vm => vm.OnlyInstalled, x => x.OnlyInstalledCheckbox.IsChecked) .DisposeWith(dispose); this.BindStrict(ViewModel, vm => vm.ShowNSFW, x => x.ShowNSFW.IsChecked)