UI - Use PropertyChanged.SourceGenerator in workshop

This commit is contained in:
Robert committed 2023-10-20 20:00:07 +02:00
1 parent 8f1509fc28
commit d656c6960d
28 files changed
+119 -411

No files matched your search

@@ -8,14 +8,15 @@ using Artemis.UI.Shared.Routing;
using ReactiveUI;
using System;
using System.Reactive.Linq;
using PropertyChanged.SourceGenerator;
namespace Artemis.UI.Screens.Workshop.Entries;
public class EntriesViewModel : RoutableHostScreen<RoutableScreen>
public partial class EntriesViewModel : RoutableHostScreen<RoutableScreen>
{
private readonly IRouter _router;
private RouteViewModel? _selectedTab;
private ObservableAsPropertyHelper<bool>? _viewingDetails;
[Notify] private RouteViewModel? _selectedTab;
public EntriesViewModel(IRouter router)
{
@@ -44,12 +45,6 @@ public class EntriesViewModel : RoutableHostScreen<RoutableScreen>
public bool ViewingDetails => _viewingDetails?.Value ?? false;
public ObservableCollection<RouteViewModel> Tabs { get; }
public RouteViewModel? SelectedTab
{
get => _selectedTab;
set => RaiseAndSetIfChanged(ref _selectedTab, value);
}
public override async Task OnNavigating(NavigationArguments args, CancellationToken cancellationToken)
{
SelectedTab = Tabs.FirstOrDefault(t => t.Matches(args.Path));
@@ -1,18 +1,19 @@
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using PropertyChanged.SourceGenerator;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.Entries;
public class EntryListInputViewModel : ViewModelBase
public partial class EntryListInputViewModel : ViewModelBase
{
private static string? _lastSearch;
private readonly PluginSetting<int> _entriesPerPage;
private readonly PluginSetting<int> _sortBy;
private string? _search;
private string _searchWatermark = "Search";
private int _totalCount;
[Notify] private string _searchWatermark = "Search";
[Notify] private int _totalCount;
public EntryListInputViewModel(ISettingsService settingsService)
{
@@ -22,13 +23,7 @@ public class EntryListInputViewModel : ViewModelBase
_entriesPerPage.AutoSave = true;
_sortBy.AutoSave = true;
}
public string SearchWatermark
{
get => _searchWatermark;
set => RaiseAndSetIfChanged(ref _searchWatermark, value);
}
public string? Search
{
get => _search;
@@ -59,15 +54,8 @@ public class EntryListInputViewModel : ViewModelBase
}
}
public int TotalCount
{
get => _totalCount;
set => RaiseAndSetIfChanged(ref _totalCount, value);
}
public void ClearLastSearch()
{
_lastSearch = null;
}
}
@@ -13,12 +13,13 @@ using Artemis.UI.Shared.Services.Builders;
using Artemis.WebClient.Workshop;
using Avalonia.Threading;
using DynamicData;
using PropertyChanged.SourceGenerator;
using ReactiveUI;
using StrawberryShake;
namespace Artemis.UI.Screens.Workshop.Entries;
public abstract class EntryListViewModel : RoutableScreen<WorkshopListParameters>
public abstract partial class EntryListViewModel : RoutableScreen<WorkshopListParameters>
{
private readonly SourceList<IGetEntries_Entries_Items> _entries = new();
private readonly ObservableAsPropertyHelper<bool> _isLoading;
@@ -26,10 +27,9 @@ public abstract class EntryListViewModel : RoutableScreen<WorkshopListParameters
private readonly string _route;
private readonly ObservableAsPropertyHelper<bool> _showPagination;
private readonly IWorkshopClient _workshopClient;
private int _loadedPage = -1;
private int _page;
private int _totalPages = 1;
[Notify] private int _page;
[Notify] private int _loadedPage = -1;
[Notify] private int _totalPages = 1;
protected EntryListViewModel(string route,
IWorkshopClient workshopClient,
@@ -74,26 +74,7 @@ public abstract class EntryListViewModel : RoutableScreen<WorkshopListParameters
public EntryListInputViewModel InputViewModel { get; }
public ReadOnlyObservableCollection<EntryListItemViewModel> Entries { get; }
public int Page
{
get => _page;
set => RaiseAndSetIfChanged(ref _page, value);
}
public int LoadedPage
{
get => _loadedPage;
set => RaiseAndSetIfChanged(ref _loadedPage, value);
}
public int TotalPages
{
get => _totalPages;
set => RaiseAndSetIfChanged(ref _totalPages, value);
}
public override async Task OnNavigating(WorkshopListParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
{
Page = Math.Max(1, parameters.Page);
@@ -16,6 +16,7 @@ using AvaloniaEdit.Document;
using DynamicData;
using DynamicData.Aggregation;
using DynamicData.Binding;
using PropertyChanged.SourceGenerator;
using ReactiveUI;
using ReactiveUI.Validation.Extensions;
using ReactiveUI.Validation.Helpers;
@@ -23,20 +24,19 @@ using StrawberryShake;
namespace Artemis.UI.Screens.Workshop.Entries;
public class EntrySpecificationsViewModel : ValidatableViewModelBase
public partial class EntrySpecificationsViewModel : ValidatableViewModelBase
{
private readonly ObservableAsPropertyHelper<bool> _categoriesValid;
private readonly ObservableAsPropertyHelper<bool> _iconValid;
private readonly ObservableAsPropertyHelper<bool> _descriptionValid;
private readonly IWorkshopClient _workshopClient;
private readonly IWindowService _windowService;
private string _description = string.Empty;
private Bitmap? _iconBitmap;
private TextDocument? _markdownDocument;
private string _name = string.Empty;
private string _summary = string.Empty;
private bool _iconChanged;
[Notify] private string _name = string.Empty;
[Notify] private string _summary = string.Empty;
[Notify] private string _description = string.Empty;
[Notify] private Bitmap? _iconBitmap;
[Notify] private TextDocument? _markdownDocument;
[Notify(Setter.Private)] private bool _iconChanged;
public EntrySpecificationsViewModel(IWorkshopClient workshopClient, IWindowService windowService)
{
@@ -91,42 +91,6 @@ public class EntrySpecificationsViewModel : ValidatableViewModelBase
public bool IconValid => _iconValid.Value;
public bool DescriptionValid => _descriptionValid.Value;
public string Name
{
get => _name;
set => RaiseAndSetIfChanged(ref _name, value);
}
public string Summary
{
get => _summary;
set => RaiseAndSetIfChanged(ref _summary, value);
}
public string Description
{
get => _description;
set => RaiseAndSetIfChanged(ref _description, value);
}
public Bitmap? IconBitmap
{
get => _iconBitmap;
set => RaiseAndSetIfChanged(ref _iconBitmap, value);
}
public TextDocument? MarkdownDocument
{
get => _markdownDocument;
set => RaiseAndSetIfChanged(ref _markdownDocument, value);
}
public bool IconChanged
{
get => _iconChanged;
private set => RaiseAndSetIfChanged(ref _iconChanged, value);
}
public List<long> PreselectedCategories { get; set; } = new();
private void MarkdownDocumentOnTextChanged(object? sender, EventArgs e)