Added functionality to the Searchbar

This commit is contained in:
erri120 2020-02-15 16:45:53 +01:00
parent 0af7a90b0e
commit b250a89684
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
2 changed files with 28 additions and 2 deletions

View File

@ -1,4 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.Lib;
@ -16,9 +21,28 @@ namespace Wabbajack
public IEnumerable<Archive> Archives => Manifest.Archives;
[Reactive]
public string SearchTerm { get; set; }
private readonly ObservableAsPropertyHelper<IEnumerable<Archive>> _searchResults;
public IEnumerable<Archive> SearchResults => _searchResults.Value;
public ManifestVM(Manifest manifest)
{
Manifest = manifest;
_searchResults =
this.WhenAnyValue(x => x.SearchTerm)
.Throttle(TimeSpan.FromMilliseconds(800))
.Select(term => term?.Trim())
.DistinctUntilChanged()
.Select(term =>
{
return string.IsNullOrWhiteSpace(term)
? Archives
: Archives.Where(x => x.Name.StartsWith(term));
})
.ToGuiProperty(this, nameof(SearchResults), Archives);
}
}
}

View File

@ -36,12 +36,14 @@ namespace Wabbajack
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Description, x => x.Description.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Archives, x => x.ModsList.ItemsSource)
this.OneWayBind(ViewModel, x => x.SearchResults, x => x.ModsList.ItemsSource)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.InstallSize, x => x.InstallSize.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.DownloadSize, x => x.DownloadSize.Text)
.DisposeWith(disposable);
this.Bind(ViewModel, x => x.SearchTerm, x => x.SearchBar.Text)
.DisposeWith(disposable);
});
}