fix: change schemas list to prevent layout cycle

This commit is contained in:
estrogen elf
2025-06-17 21:50:53 -05:00
parent 57334535cf
commit 876f50607f
9 changed files with 100 additions and 127 deletions

View File

@@ -79,6 +79,9 @@
<Compile Update="Views\Pages\Endpoints\PluginView.axaml.cs"> <Compile Update="Views\Pages\Endpoints\PluginView.axaml.cs">
<DependentUpon>PluginView.axaml</DependentUpon> <DependentUpon>PluginView.axaml</DependentUpon>
</Compile> </Compile>
<Compile Update="Views\Pages\Schemas\SchemaSearchDetailsView.axaml.cs">
<DependentUpon>SchemaSearchDetailsView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Pages\WebSocket\WebsocketView.axaml.cs"> <Compile Update="Views\Pages\WebSocket\WebsocketView.axaml.cs">
<DependentUpon>WebSocketView.axaml</DependentUpon> <DependentUpon>WebSocketView.axaml</DependentUpon>
</Compile> </Compile>
@@ -87,4 +90,8 @@
<ItemGroup> <ItemGroup>
<Folder Include="Assets\Users\" /> <Folder Include="Assets\Users\" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="ViewModels\Pages\Schemas\SchemaSearchDetailsViewModel.cs" />
</ItemGroup>
</Project> </Project>

View File

@@ -70,7 +70,7 @@ class Program
var locator = new ViewLocator(); var locator = new ViewLocator();
// MAIN WINDOW // MAIN WINDOW
locator.Register<NotificationViewModel>(() => new NotificationView()); locator.Register<NotificationViewModel>(() => new NotificationView());
locator.Register<SchemaSearchDetailsViewModel>(() => new SchemaSearchDetailsView()); locator.Register<ViewModels.MainWindow.SchemaSearchDetailsViewModel>(() => new Views.MainWindow.SchemaSearchDetailsView());
locator.Register<SchemaViewModel>(() => new SchemaView()); locator.Register<SchemaViewModel>(() => new SchemaView());
// ABOUT // ABOUT
locator.Register<AboutViewModel>(() => new AboutView()); locator.Register<AboutViewModel>(() => new AboutView());
@@ -89,7 +89,7 @@ class Program
locator.Register<LibraryViewModel>(() => new LibraryView()); locator.Register<LibraryViewModel>(() => new LibraryView());
// SCHEMAS // SCHEMAS
locator.Register<SchemasViewModel>(() => new SchemasView()); locator.Register<SchemasViewModel>(() => new SchemasView());
locator.Register<SchemaItemViewModel>(() => new SchemaItemView()); locator.Register<ViewModels.Pages.Schemas.SchemaSearchDetailsViewModel>(() => new Views.Pages.Schemas.SchemaSearchDetailsView());
// WEBSOCKET // WEBSOCKET
locator.Register<WebSocketViewModel>(() => new WebSocketView()); locator.Register<WebSocketViewModel>(() => new WebSocketView());
locator.Register<EventViewModel>(() => new EventView()); locator.Register<EventViewModel>(() => new EventView());

View File

@@ -1,22 +0,0 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Needlework.Net.ViewModels.Pages.Endpoints;
using System.Collections.Generic;
namespace Needlework.Net.ViewModels.Pages.Schemas
{
public partial class SchemaItemViewModel : ObservableObject
{
public SchemaItemViewModel(PropertyClassViewModel vm)
{
Id = vm.Id;
PropertyFields = vm.PropertyFields;
PropertyEnums = vm.PropertyEnums;
}
public string Id { get; }
public List<PropertyFieldViewModel> PropertyFields { get; } = [];
public List<PropertyEnumViewModel> PropertyEnums { get; } = [];
}
}

View File

@@ -0,0 +1,26 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Needlework.Net.ViewModels.Pages.Endpoints;
using System;
namespace Needlework.Net.ViewModels.Pages.Schemas
{
public partial class SchemaSearchDetailsViewModel : ObservableObject
{
public SchemaSearchDetailsViewModel(Tab tab, PropertyClassViewModel vm)
{
Tab = tab;
Id = vm.Id;
}
public string Id { get; }
public Tab Tab { get; }
public string Document => Tab switch
{
Tab.LCU => "LCU",
Tab.GameClient => "Game Client",
_ => throw new NotImplementedException()
};
}
}

View File

@@ -3,7 +3,6 @@ using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using DebounceThrottle; using DebounceThrottle;
using Needlework.Net.Helpers; using Needlework.Net.Helpers;
using Needlework.Net.Models;
using Needlework.Net.ViewModels.Pages.Endpoints; using Needlework.Net.ViewModels.Pages.Endpoints;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -18,9 +17,7 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
private readonly DocumentService _documentService; private readonly DocumentService _documentService;
public record SchemaTab(string Key, Tab Tab); private List<SchemaSearchDetailsViewModel> _schemas = [];
private List<SchemaTab> _schemas = [];
public SchemasViewModel(DocumentService documentService) : base("Schemas", "fa-solid fa-file-lines", -100) public SchemasViewModel(DocumentService documentService) : base("Schemas", "fa-solid fa-file-lines", -100)
{ {
@@ -34,7 +31,7 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
private string? _search; private string? _search;
[ObservableProperty] [ObservableProperty]
private List<SchemaItemViewModel> _schemaItems = []; private List<SchemaSearchDetailsViewModel> _schemaItems = [];
[ObservableProperty] [ObservableProperty]
private Vector _offset = new(); private Vector _offset = new();
@@ -43,38 +40,18 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
{ {
_debounceDispatcher.Debounce(() => _debounceDispatcher.Debounce(() =>
{ {
Task.Run(async () =>
{
var lcuSchemaDocument = await _documentService.GetLcuSchemaDocumentAsync();
var lolClientDocument = await _documentService.GetLolClientDocumentAsync();
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
{ {
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
SchemaItems = _schemas.Select((schema) => ToSchemaItemViewModel(schema, lcuSchemaDocument, lolClientDocument)) SchemaItems = _schemas.ToList();
.ToList();
}); });
return; return;
} }
var items = _schemas.Where(schema => schema.Key.Contains(value, StringComparison.OrdinalIgnoreCase)) var items = _schemas.Where(schema => schema.Id.Contains(value, StringComparison.OrdinalIgnoreCase))
.Select((schema) => ToSchemaItemViewModel(schema, lcuSchemaDocument, lolClientDocument))
.ToList(); .ToList();
Dispatcher.UIThread.Invoke(() => { SchemaItems = items; }); Dispatcher.UIThread.Invoke(() => { SchemaItems = items; });
}); });
});
}
private SchemaItemViewModel ToSchemaItemViewModel(SchemaTab schema, Document lcuSchemaDocument, Document lolClientDocument)
{
var document = schema.Tab switch
{
Tab.LCU => lcuSchemaDocument.OpenApiDocument,
Tab.GameClient => lolClientDocument.OpenApiDocument,
_ => throw new NotImplementedException()
};
var vm = OpenApiHelpers.WalkSchema(document.Components.Schemas[schema.Key], document);
return new SchemaItemViewModel(vm);
} }
public override async Task InitializeAsync() public override async Task InitializeAsync()
@@ -84,13 +61,11 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
var schemas = Enumerable.Concat( var schemas = Enumerable.Concat(
lcuSchemaDocument.OpenApiDocument.Components.Schemas.Keys.Select(key => new SchemaTab(key, Tab.LCU)), lcuSchemaDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.LCU, OpenApiHelpers.WalkSchema(schema, lcuSchemaDocument.OpenApiDocument))),
lolClientDocument.OpenApiDocument.Components.Schemas.Keys.Select(key => new SchemaTab(key, Tab.GameClient)) lolClientDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.GameClient, OpenApiHelpers.WalkSchema(schema, lolClientDocument.OpenApiDocument)))
).ToList(); ).ToList();
_schemas = schemas; _schemas = schemas;
SchemaItems = schemas SchemaItems = schemas.ToList();
.Select((schema) => ToSchemaItemViewModel(schema, lcuSchemaDocument, lolClientDocument))
.ToList();
IsBusy = false; IsBusy = false;
}); });
} }

View File

@@ -1,59 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:Needlework.Net.ViewModels.Pages.Schemas"
xmlns:controls="using:Needlework.Net.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Needlework.Net.Views.Pages.Schemas.SchemaItemView"
x:DataType="vm:SchemaItemViewModel">
<UserControl.Styles>
<Style Selector="DataGrid">
<Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource ControlElevationBorderBrush}"/>
</Style>
<Style Selector="DataGridColumnHeader TextBlock">
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
</Style>
<Style Selector="DataGridRow DataGridCell">
<Setter Property="FontSize" Value="12"></Setter>
</Style>
<Style Selector="DataGridRow">
<Setter Property="Margin" Value="0 0 0 4"></Setter>
</Style>
</UserControl.Styles>
<Border CornerRadius="4"
ClipToBounds="True"
BorderBrush="{DynamicResource ControlStrokeColorOnAccentTertiaryBrush}"
BorderThickness="1">
<StackPanel>
<Border Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
BorderThickness="0 0 0 1"
BorderBrush="{DynamicResource ControlStrokeColorOnAccentTertiaryBrush}"
Padding="12">
<TextBlock FontSize="12"
FontWeight="DemiBold"
Text="{Binding Id}"/>
</Border>
<Border Background="{DynamicResource CardBackgroundFillColorSecondaryBrush}"
Padding="12"
IsVisible="{Binding PropertyFields, Converter={StaticResource EnumerableToVisibilityConverter}}">
<DataGrid
ItemsSource="{Binding PropertyFields}"
AutoGenerateColumns="True"
IsReadOnly="True"
GridLinesVisibility="Horizontal">
</DataGrid>
</Border>
<Border Background="{DynamicResource CardBackgroundFillColorSecondaryBrush}"
Padding="12"
IsVisible="{Binding PropertyEnums, Converter={StaticResource EnumerableToVisibilityConverter}}">
<DataGrid
ItemsSource="{Binding PropertyEnums}"
AutoGenerateColumns="True"
IsReadOnly="True"
GridLinesVisibility="Horizontal">
</DataGrid>
</Border>
</StackPanel>
</Border>
</UserControl>

View File

@@ -0,0 +1,46 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:Needlework.Net.ViewModels.Pages.Schemas"
xmlns:controls="using:Needlework.Net.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Needlework.Net.Views.Pages.Schemas.SchemaSearchDetailsView"
x:DataType="vm:SchemaSearchDetailsViewModel">
<UserControl.Styles>
<Style Selector="DataGrid">
<Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource ControlElevationBorderBrush}"/>
</Style>
<Style Selector="DataGridColumnHeader TextBlock">
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
</Style>
<Style Selector="DataGridRow DataGridCell">
<Setter Property="FontSize" Value="12"></Setter>
</Style>
<Style Selector="DataGridRow">
<Setter Property="Margin" Value="0 0 0 4"></Setter>
</Style>
</UserControl.Styles>
<Button CornerRadius="4"
ClipToBounds="True"
BorderBrush="{DynamicResource ControlStrokeColorOnAccentTertiaryBrush}"
Background="Transparent"
Padding="0"
BorderThickness="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<Border Grid.Column="0"
Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
Padding="12">
<StackPanel>
<TextBlock FontSize="12"
FontWeight="DemiBold"
Text="{Binding Id}"/>
<TextBlock FontSize="12"
Text="{Binding Document}"
Theme="{StaticResource CaptionTextBlockStyle}"
Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"/>
</StackPanel>
</Border>
</Button>
</UserControl>

View File

@@ -2,9 +2,9 @@ using Avalonia.Controls;
namespace Needlework.Net.Views.Pages.Schemas; namespace Needlework.Net.Views.Pages.Schemas;
public partial class SchemaItemView : UserControl public partial class SchemaSearchDetailsView : UserControl
{ {
public SchemaItemView() public SchemaSearchDetailsView()
{ {
InitializeComponent(); InitializeComponent();
} }

View File

@@ -23,13 +23,13 @@
Offset="{Binding Offset, Mode=TwoWay}"> Offset="{Binding Offset, Mode=TwoWay}">
<ItemsControl ItemsSource="{Binding SchemaItems}"> <ItemsControl ItemsSource="{Binding SchemaItems}">
<ItemsControl.Styles> <ItemsControl.Styles>
<Style Selector="views|SchemaItemView"> <Style Selector="views|SchemaSearchDetailsView">
<Setter Property="Margin" Value="0 0 0 8"/> <Setter Property="Margin" Value="0 0 0 8" />
</Style> </Style>
</ItemsControl.Styles> </ItemsControl.Styles>
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<VirtualizingStackPanel/> <VirtualizingStackPanel />
</ItemsPanelTemplate> </ItemsPanelTemplate>
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>