wip: Try to incorporate RxUI into custom format group parser

gui
Robert Dailey 2 years ago
parent 5744ca3bba
commit 9eb1dd47ba

@ -0,0 +1,24 @@
@page "/custom-format"
@inherits ReactiveInjectableComponentBase<CustomFormatViewModel>
@if (ViewModel is null)
{
return;
}
<MudPaper>
<CustomFormatGroup ViewModel="@ViewModel.Groups[0]" />
</MudPaper>
@code {
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
if (ViewModel != null)
{
await ViewModel.OnInit.Execute();
}
}
}

@ -0,0 +1,20 @@
@inherits ReactiveComponentBase<CustomFormatGroupViewModel>
@if (ViewModel is null)
{
return;
}
<MudPaper>
<h1>@ViewModel.GroupName</h1>
@foreach (var cf in ViewModel.CustomFormats)
{
<h2>@cf.Name</h2>
}
</MudPaper>
@code {
}

@ -1,21 +1,41 @@
using System.Reactive;
using System.Reactive.Linq;
using ReactiveUI;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Processors;
namespace Recyclarr.Gui.ViewModels;
public class CustomFormatGroupViewModel : ReactiveObject
{
public string GroupName { get; set; }
public ICollection<CustomFormatGroupItem> CustomFormats { get; set; }
public string GroupName { get; }
public ICollection<CustomFormatData> CustomFormats { get; }
public CustomFormatGroupViewModel()
public CustomFormatGroupViewModel(string groupName, ICollection<CustomFormatData> customFormats)
{
GroupName = groupName;
CustomFormats = customFormats;
}
}
public class CustomFormatViewModel : ReactiveObject
{
public CustomFormatViewModel()
private readonly ICustomFormatLookup _cfLookup;
private readonly List<CustomFormatGroupViewModel> _groups = new();
public List<CustomFormatGroupViewModel> Groups => _groups;
public ReactiveCommand<Unit, Unit> OnInit;
public CustomFormatViewModel(ICustomFormatLookup cfLookup)
{
_cfLookup = cfLookup;
OnInit = ReactiveCommand.Create(() =>
{
foreach (var (groupName, cfs) in _cfLookup.MapAllCustomFormats())
{
}
});
}
}

@ -9,3 +9,6 @@
@using MudBlazor
@using Recyclarr.Gui
@using Recyclarr.Gui.Shared
@using Recyclarr.Gui.ViewModels
@using ReactiveUI.Blazor
@using System.Reactive.Linq

@ -4,5 +4,5 @@ namespace TrashLib.Radarr.CustomFormat.Guide;
public interface IRadarrGuideService
{
ICollection<CustomFormatData> GetCustomFormatData();
IObservable<CustomFormatData> GetCustomFormatData();
}

@ -23,7 +23,7 @@ public class LocalRepoCustomFormatJsonParser : IRadarrGuideService
_fs = fs;
}
public ICollection<CustomFormatData> GetCustomFormatData()
public IObservable<CustomFormatData> GetCustomFormatData()
{
var jsonDir = _paths.RepoDirectory
.SubDirectory("docs")
@ -33,9 +33,7 @@ public class LocalRepoCustomFormatJsonParser : IRadarrGuideService
return jsonDir.EnumerateFiles("*.json").ToObservable()
.Select(x => Observable.Defer(() => LoadJsonFromFile(x)))
.Merge(8)
.NotNull()
.ToEnumerable()
.ToList();
.NotNull();
}
private IObservable<CustomFormatData?> LoadJsonFromFile(IFileInfo file)

@ -1,10 +1,12 @@
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using Common.Extensions;
using TrashLib.Radarr.CustomFormat.Guide;
using TrashLib.Radarr.CustomFormat.Models;
namespace TrashLib.Radarr.CustomFormat.Processors;
public class CustomFormatLookup
public class CustomFormatLookup : ICustomFormatLookup
{
private readonly ICustomFormatGroupParser _parser;
private readonly IRadarrGuideService _guide;
@ -22,8 +24,17 @@ public class CustomFormatLookup
guideCfs.FirstOrDefault(x => x.Name.EqualsIgnoreCase(groupItem.Name));
}
private async Task<IDictionary<string, ReadOnlyCollection<CustomFormatGroupItem>>> ParseGroupsAsync()
{
}
public Dictionary<string, List<CustomFormatData>> MapAllCustomFormats()
{
Observable.Defer(() => _parser.Parse().ToObservable())
.ToDictionary(
x => x.Key,
x => x.Value.Select(y => MatchDataWithCellEntry(guideCfs, y)).NotNull().ToList());
var guideCfs = _guide.GetCustomFormatData();
var groups = _parser.Parse();

@ -0,0 +1,8 @@
using TrashLib.Radarr.CustomFormat.Models;
namespace TrashLib.Radarr.CustomFormat.Processors;
public interface ICustomFormatLookup
{
Dictionary<string, List<CustomFormatData>> MapAllCustomFormats();
}
Loading…
Cancel
Save