More project base

This commit is contained in:
2022-04-01 20:38:43 +02:00
parent d0edf85e98
commit 8e09bf41bb
76 changed files with 3589 additions and 78 deletions

View File

@@ -1,7 +1,65 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using FileTime.Core.Models;
namespace FileTime.Core.Services
{
public class Tab : ITab
{
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
public IObservable<IContainer?> CurrentLocation { get; }
public IObservable<IEnumerable<IItem>> CurrentItems { get; }
public IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
public Tab()
{
CurrentLocation = _currentLocation.AsObservable();
CurrentItems = _currentLocation
.Select(c =>
Observable.FromAsync(async () =>
c == null
? Enumerable.Empty<IItem>()
: await c.Items
.ToAsyncEnumerable()
.SelectAwait(
async i =>
{
try
{
//TODO: force create by AbsolutePath name
return await i.ContentProvider.GetItemByFullNameAsync(i.Path);
}
catch { return null!; }
}
)
.Where(i => i != null)
.ToListAsync()
)
)
.Merge(Constants.MaximumObservableMergeOperations);
CurrentSelectedItem = CurrentLocation.Select(GetSelectedItemByLocation).Merge(_currentSelectedItem).Throttle(TimeSpan.FromMilliseconds(500));
CurrentItems.Subscribe(c =>
{
;
});
}
public void Init(IContainer currentLocation)
{
_currentLocation.OnNext(currentLocation);
}
private IAbsolutePath? GetSelectedItemByLocation(IContainer? currentLocation)
{
return currentLocation?.Items[0];
}
public void ChangeLocation(IContainer newLocation)
{
_currentLocation.OnNext(newLocation);
}
}
}