mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Added functionality to the Searchbar
This commit is contained in:
parent
0af7a90b0e
commit
b250a89684
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user