Show children
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace FileTime.App.Core.Extensions
|
||||
{
|
||||
public static class ObservableExtensions
|
||||
{
|
||||
public static IObservable<T> WhereNotNull<T>(this IObservable<T?> source) => source.Where(c => c != null)!;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="morelinq" Version="3.3.2" />
|
||||
<PackageReference Include="MvvmGen" Version="1.1.5" />
|
||||
<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
|
||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace FileTime.App.Core.Services
|
||||
|
||||
private async Task GoUp()
|
||||
{
|
||||
if (_currentLocation?.Parent is not IAbsolutePath parentPath || await parentPath.ResolveAsync() is not IContainer newContainer) return;
|
||||
if (_currentLocation?.Parent is not IAbsolutePath parentPath || await parentPath.ResolveAsyncSafe() is not IContainer newContainer) return;
|
||||
_selectedTab?.Tab?.SetCurrentLocation(newContainer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.App.Core.Extensions;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -24,8 +26,9 @@ namespace FileTime.App.Core.ViewModels
|
||||
|
||||
public IObservable<IContainer?> CurrentLocation { get; private set; } = null!;
|
||||
public IObservable<IItemViewModel?> CurrentSelectedItem { get; private set; } = null!;
|
||||
public IObservable<IEnumerable<IItemViewModel>> CurrentItems { get; private set; } = null!;
|
||||
public IObservable<IReadOnlyList<IItemViewModel>> CurrentItems { get; private set; } = null!;
|
||||
public IObservable<IEnumerable<FullName>> MarkedItems { get; }
|
||||
public IObservable<IReadOnlyList<IItemViewModel>?> SelectedsChildren { get; private set; } = null!;
|
||||
|
||||
public TabViewModel(
|
||||
IServiceProvider serviceProvider,
|
||||
@@ -46,7 +49,7 @@ namespace FileTime.App.Core.ViewModels
|
||||
TabNumber = tabNumber;
|
||||
|
||||
CurrentLocation = tab.CurrentLocation.AsObservable();
|
||||
CurrentItems = tab.CurrentItems.Select(items => items.Select(MapItemToViewModel).ToList()).Publish(Enumerable.Empty<IItemViewModel>()).RefCount();
|
||||
CurrentItems = tab.CurrentItems.Select(items => items.Select(MapItemToViewModel).ToList()).Publish(new List<IItemViewModel>()).RefCount();
|
||||
CurrentSelectedItem =
|
||||
Observable.CombineLatest(
|
||||
CurrentItems,
|
||||
@@ -55,7 +58,34 @@ namespace FileTime.App.Core.ViewModels
|
||||
)
|
||||
.Publish(null)
|
||||
.RefCount();
|
||||
|
||||
var currentSelectedItemThrottled = CurrentSelectedItem.Throttle(TimeSpan.FromMilliseconds(250)).Publish(null).RefCount();
|
||||
SelectedsChildren = Observable.Merge(
|
||||
currentSelectedItemThrottled
|
||||
.WhereNotNull()
|
||||
.OfType<IContainerViewModel>()
|
||||
.Where(c => c?.Container is not null)
|
||||
.Select(c => c.Container!.Items)
|
||||
.Switch()
|
||||
.Select(items => Observable.FromAsync(async () => await Map(items)))
|
||||
.Switch()
|
||||
.Select(items => items?.Select(MapItemToViewModel).ToList()),
|
||||
currentSelectedItemThrottled
|
||||
.Where(c => c is null || c is not IContainerViewModel)
|
||||
.Select(_ => (IReadOnlyList<IItemViewModel>?)null)
|
||||
);
|
||||
|
||||
tab.CurrentLocation.Subscribe((_) => _markedItems.OnNext(Enumerable.Empty<FullName>()));
|
||||
|
||||
static async Task<List<IItem>?> Map(IEnumerable<IAbsolutePath>? items)
|
||||
{
|
||||
if (items == null) return null;
|
||||
|
||||
return await items
|
||||
.ToAsyncEnumerable()
|
||||
.SelectAwait(async i => await i.ResolveAsync(true))
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private IItemViewModel MapItemToViewModel(IItem item, int index)
|
||||
|
||||
Reference in New Issue
Block a user