From f9285a2bef8a38ea5cb1fb081f2b77c3e3985f0f Mon Sep 17 00:00:00 2001 From: estrogen elf <87099578+BlossomiShymae@users.noreply.github.com> Date: Tue, 17 Jun 2025 22:52:14 -0500 Subject: [PATCH] feat: display clicked schema to pane --- Needlework.Net/Models/SchemaPaneItem.cs | 8 ++++++ Needlework.Net/Program.cs | 1 + Needlework.Net/Services/SchemaPaneService.cs | 20 +++++++++++++++ .../MainWindow/MainWindowViewModel.cs | 25 ++++++++++++++++++- .../Schemas/SchemaSearchDetailsViewModel.cs | 14 ++++++++++- .../Pages/Schemas/SchemasViewModel.cs | 10 +++++--- .../Views/MainWindow/MainWindowView.axaml | 6 +++++ .../Schemas/SchemaSearchDetailsView.axaml | 3 ++- 8 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 Needlework.Net/Models/SchemaPaneItem.cs create mode 100644 Needlework.Net/Services/SchemaPaneService.cs diff --git a/Needlework.Net/Models/SchemaPaneItem.cs b/Needlework.Net/Models/SchemaPaneItem.cs new file mode 100644 index 0000000..686b4c3 --- /dev/null +++ b/Needlework.Net/Models/SchemaPaneItem.cs @@ -0,0 +1,8 @@ +using Needlework.Net.ViewModels.Pages.Endpoints; + +namespace Needlework.Net.Models +{ + public record SchemaPaneItem(string Key, Tab Tab) + { + } +} diff --git a/Needlework.Net/Program.cs b/Needlework.Net/Program.cs index e5a1255..2e600ad 100644 --- a/Needlework.Net/Program.cs +++ b/Needlework.Net/Program.cs @@ -102,6 +102,7 @@ class Program builder.AddSingleton(); builder.AddSingleton(); builder.AddSingleton(); + builder.AddSingleton(); builder.AddSingleton(new FlurlClientCache() .Add("GithubClient", "https://api.github.com") .Add("GithubUserContentClient", "https://raw.githubusercontent.com") diff --git a/Needlework.Net/Services/SchemaPaneService.cs b/Needlework.Net/Services/SchemaPaneService.cs new file mode 100644 index 0000000..d1a9d2e --- /dev/null +++ b/Needlework.Net/Services/SchemaPaneService.cs @@ -0,0 +1,20 @@ +using Needlework.Net.Models; +using Needlework.Net.ViewModels.Pages.Endpoints; +using System; +using System.Reactive.Subjects; + +namespace Needlework.Net.Services +{ + public class SchemaPaneService + { + private readonly Subject _schemaPaneItemsSubject = new(); + + public IObservable SchemaPaneItems { get { return _schemaPaneItemsSubject; } } + + public void Add(string key, Tab tab) + { + var schemaPaneItem = new SchemaPaneItem(key, tab); + _schemaPaneItemsSubject.OnNext(schemaPaneItem); + } + } +} diff --git a/Needlework.Net/ViewModels/MainWindow/MainWindowViewModel.cs b/Needlework.Net/ViewModels/MainWindow/MainWindowViewModel.cs index 786be02..354d0d1 100644 --- a/Needlework.Net/ViewModels/MainWindow/MainWindowViewModel.cs +++ b/Needlework.Net/ViewModels/MainWindow/MainWindowViewModel.cs @@ -41,15 +41,18 @@ public partial class MainWindowViewModel private readonly DialogService _dialogService; + private readonly SchemaPaneService _schemaPaneService; + private readonly IDisposable _checkForUpdatesDisposable; private readonly IDisposable _checkForSchemaVersionDisposable; - public MainWindowViewModel(IEnumerable pages, DialogService dialogService, DocumentService documentService, NotificationService notificationService, IFlurlClientCache clients) + public MainWindowViewModel(IEnumerable pages, DialogService dialogService, DocumentService documentService, NotificationService notificationService, IFlurlClientCache clients, SchemaPaneService schemaPaneService) { _dialogService = dialogService; _documentService = documentService; _notificationService = notificationService; + _schemaPaneService = schemaPaneService; _githubClient = clients.Get("GithubClient"); NavigationViewItems = pages @@ -68,6 +71,26 @@ public partial class MainWindowViewModel Notifications.Remove(vm); }); + _schemaPaneService.SchemaPaneItems.Subscribe(async item => + { + var document = item.Tab switch + { + Pages.Endpoints.Tab.LCU => await documentService.GetLcuSchemaDocumentAsync(), + Pages.Endpoints.Tab.GameClient => await documentService.GetLolClientDocumentAsync(), + _ => throw new NotImplementedException() + }; + var propertyClassViewModel = OpenApiHelpers.WalkSchema(document.OpenApiDocument.Components.Schemas[item.Key], document.OpenApiDocument); + var schemaViewModel = new SchemaViewModel(propertyClassViewModel); + if (Schemas.ToList().Find(schema => schema.Id == schemaViewModel.Id) == null) + { + Schemas.Add(schemaViewModel); + IsPaneOpen = true; + + OpenSchemaPaneCommand.NotifyCanExecuteChanged(); + CloseSchemaAllCommand.NotifyCanExecuteChanged(); + } + }); + _checkForUpdatesDisposable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromMinutes(10)) .Select(time => Unit.Default) .Subscribe(async _ => diff --git a/Needlework.Net/ViewModels/Pages/Schemas/SchemaSearchDetailsViewModel.cs b/Needlework.Net/ViewModels/Pages/Schemas/SchemaSearchDetailsViewModel.cs index 8b9df9b..822fd01 100644 --- a/Needlework.Net/ViewModels/Pages/Schemas/SchemaSearchDetailsViewModel.cs +++ b/Needlework.Net/ViewModels/Pages/Schemas/SchemaSearchDetailsViewModel.cs @@ -1,4 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Needlework.Net.Services; using Needlework.Net.ViewModels.Pages.Endpoints; using System; @@ -6,8 +8,12 @@ namespace Needlework.Net.ViewModels.Pages.Schemas { public partial class SchemaSearchDetailsViewModel : ObservableObject { - public SchemaSearchDetailsViewModel(Tab tab, PropertyClassViewModel vm) + private readonly SchemaPaneService _schemaPaneService; + + public SchemaSearchDetailsViewModel(Tab tab, PropertyClassViewModel vm, SchemaPaneService schemaPaneService) { + _schemaPaneService = schemaPaneService; + Tab = tab; Id = vm.Id; } @@ -22,5 +28,11 @@ namespace Needlework.Net.ViewModels.Pages.Schemas Tab.GameClient => "Game Client", _ => throw new NotImplementedException() }; + + [RelayCommand] + private void Display() + { + _schemaPaneService.Add(Id, Tab); + } } } diff --git a/Needlework.Net/ViewModels/Pages/Schemas/SchemasViewModel.cs b/Needlework.Net/ViewModels/Pages/Schemas/SchemasViewModel.cs index 64853d5..7409025 100644 --- a/Needlework.Net/ViewModels/Pages/Schemas/SchemasViewModel.cs +++ b/Needlework.Net/ViewModels/Pages/Schemas/SchemasViewModel.cs @@ -3,6 +3,7 @@ using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; using DebounceThrottle; using Needlework.Net.Helpers; +using Needlework.Net.Services; using Needlework.Net.ViewModels.Pages.Endpoints; using System; using System.Collections.Generic; @@ -17,11 +18,14 @@ namespace Needlework.Net.ViewModels.Pages.Schemas private readonly DocumentService _documentService; + private readonly SchemaPaneService _schemaPaneService; + private List _schemas = []; - public SchemasViewModel(DocumentService documentService) : base("Schemas", "fa-solid fa-file-lines", -100) + public SchemasViewModel(DocumentService documentService, SchemaPaneService schemaPaneService) : base("Schemas", "fa-solid fa-file-lines", -100) { _documentService = documentService; + _schemaPaneService = schemaPaneService; } [ObservableProperty] @@ -61,8 +65,8 @@ namespace Needlework.Net.ViewModels.Pages.Schemas Dispatcher.UIThread.Invoke(() => { var schemas = Enumerable.Concat( - lcuSchemaDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.LCU, OpenApiHelpers.WalkSchema(schema, lcuSchemaDocument.OpenApiDocument))), - lolClientDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.GameClient, OpenApiHelpers.WalkSchema(schema, lolClientDocument.OpenApiDocument))) + lcuSchemaDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.LCU, OpenApiHelpers.WalkSchema(schema, lcuSchemaDocument.OpenApiDocument), _schemaPaneService)), + lolClientDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.GameClient, OpenApiHelpers.WalkSchema(schema, lolClientDocument.OpenApiDocument), _schemaPaneService)) ).ToList(); _schemas = schemas; SchemaItems = schemas.ToList(); diff --git a/Needlework.Net/Views/MainWindow/MainWindowView.axaml b/Needlework.Net/Views/MainWindow/MainWindowView.axaml index 3e82dbb..86d8201 100644 --- a/Needlework.Net/Views/MainWindow/MainWindowView.axaml +++ b/Needlework.Net/Views/MainWindow/MainWindowView.axaml @@ -8,6 +8,7 @@ xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" xmlns:i="https://github.com/projektanker/icons.avalonia" xmlns:vm="using:Needlework.Net.ViewModels.MainWindow" + xmlns:views="using:Needlework.Net.Views.MainWindow" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Needlework.Net.Views.MainWindow.MainWindowView" x:DataType="vm:MainWindowViewModel" @@ -132,6 +133,11 @@ + + + + + diff --git a/Needlework.Net/Views/Pages/Schemas/SchemaSearchDetailsView.axaml b/Needlework.Net/Views/Pages/Schemas/SchemaSearchDetailsView.axaml index 86caedd..e3c4a5e 100644 --- a/Needlework.Net/Views/Pages/Schemas/SchemaSearchDetailsView.axaml +++ b/Needlework.Net/Views/Pages/Schemas/SchemaSearchDetailsView.axaml @@ -28,7 +28,8 @@ Padding="0" BorderThickness="1" HorizontalAlignment="Stretch" - HorizontalContentAlignment="Stretch"> + HorizontalContentAlignment="Stretch" + Command="{Binding DisplayCommand}">