Sorting buttons now update the result

This commit is contained in:
erri120 2020-02-19 17:35:34 +01:00
parent ea39485f27
commit e764e59ff6
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
using CefSharp; using CefSharp;
using DynamicData.Binding;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Wabbajack.Common; using Wabbajack.Common;
@ -43,27 +44,21 @@ namespace Wabbajack
private IEnumerable<Archive> Order(IEnumerable<Archive> list) private IEnumerable<Archive> Order(IEnumerable<Archive> list)
{ {
if (SortAscending) if (SortAscending)
{
return list.OrderBy(x =>
{
return SortEnum switch
{
SortBy.Name => x.Name,
SortBy.Size => x.Name,
_ => throw new ArgumentOutOfRangeException()
};
});
}
return list.OrderByDescending(x =>
{ {
return SortEnum switch return SortEnum switch
{ {
SortBy.Name => x.Name, SortBy.Name => list.OrderBy(x => x.Name),
SortBy.Size => x.Name, SortBy.Size => list.OrderBy(x => x.Size),
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
}); }
return SortEnum switch
{
SortBy.Name => list.OrderByDescending(x => x.Name),
SortBy.Size => list.OrderByDescending(x => x.Size),
_ => throw new ArgumentOutOfRangeException()
};
} }
public ManifestVM(Manifest manifest) public ManifestVM(Manifest manifest)
@ -73,7 +68,10 @@ namespace Wabbajack
SortByNameCommand = ReactiveCommand.Create(() => SortByNameCommand = ReactiveCommand.Create(() =>
{ {
if (SortEnum != SortBy.Name) if (SortEnum != SortBy.Name)
{
SortEnum = SortBy.Name; SortEnum = SortBy.Name;
SortAscending = true;
}
else else
SortAscending = !SortAscending; SortAscending = !SortAscending;
}); });
@ -81,20 +79,23 @@ namespace Wabbajack
SortBySizeCommand = ReactiveCommand.Create(() => SortBySizeCommand = ReactiveCommand.Create(() =>
{ {
if (SortEnum != SortBy.Size) if (SortEnum != SortBy.Size)
{
SortEnum = SortBy.Size; SortEnum = SortBy.Size;
SortAscending = true;
}
else else
SortAscending = !SortAscending; SortAscending = !SortAscending;
}); });
_searchResults = _searchResults =
this.WhenAnyValue(x => x.SearchTerm) this.WhenAnyValue(x => x.SearchTerm)
/*.CombineLatest( .CombineLatest(
this.WhenAnyValue(x => x.SortAscending), this.WhenAnyValue(x => x.SortAscending),
this.WhenAnyValue(x => x.SortEnum), this.WhenAnyValue(x => x.SortEnum),
(term, ascending, sort) => term)*/ (term, ascending, sort) => term)
.Throttle(TimeSpan.FromMilliseconds(800)) .Throttle(TimeSpan.FromMilliseconds(800))
.Select(term => term?.Trim()) .Select(term => term?.Trim())
.DistinctUntilChanged() //.DistinctUntilChanged()
.Select(term => .Select(term =>
{ {
if (string.IsNullOrWhiteSpace(term)) if (string.IsNullOrWhiteSpace(term))