mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Workshop Library - Added library pages
UI - Tweaked design to more closely match WinUI 3 gallery examples
This commit is contained in:
1 parent
e545d2f3da
commit
9c6d7329a6
25 files changed
+519
-288
No files matched your search
@@ -23,8 +23,7 @@
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Margin="0 0 10 0" Spacing="10">
|
||||
<Border Classes="card" VerticalAlignment="Top">
|
||||
<StackPanel>
|
||||
<Border CornerRadius="12"
|
||||
Background="{StaticResource ControlStrokeColorOnAccentDefault}"
|
||||
<Border CornerRadius="6"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0 0 10 0"
|
||||
Width="80"
|
||||
|
||||
@@ -10,16 +10,18 @@
|
||||
<Border Classes="router-container">
|
||||
<Grid ColumnDefinitions="300,*" Margin="10" RowDefinitions="*,Auto">
|
||||
<StackPanel Grid.Column="0" Grid.RowSpan="2" Margin="0 0 10 0" VerticalAlignment="Top">
|
||||
<TextBlock Classes="card-title" Margin="0 0 0 5">
|
||||
Categories
|
||||
</TextBlock>
|
||||
<Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
|
||||
<ContentControl Content="{CompiledBinding CategoriesViewModel}"></ContentControl>
|
||||
<Border Classes="card" VerticalAlignment="Stretch">
|
||||
<StackPanel>
|
||||
<TextBlock Theme="{StaticResource SubtitleTextBlockStyle}">Categories</TextBlock>
|
||||
<Border Classes="card-separator" />
|
||||
<ContentControl Content="{CompiledBinding CategoriesViewModel}"></ContentControl>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<ProgressBar Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" Margin="0 26 20 0" IsVisible="{CompiledBinding IsLoading}" IsIndeterminate="True"/>
|
||||
<ScrollViewer Grid.Column="1" Grid.Row="0" Margin="0 26 0 0">
|
||||
<ProgressBar Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" Margin="0 0 20 0" IsVisible="{CompiledBinding IsLoading}" IsIndeterminate="True"/>
|
||||
|
||||
<ScrollViewer Grid.Column="1" Grid.Row="0">
|
||||
<ItemsRepeater ItemsSource="{CompiledBinding Entries}" Margin="0 0 20 0">
|
||||
<ItemsRepeater.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
@@ -1,165 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Screens.Workshop.Categories;
|
||||
using Artemis.UI.Screens.Workshop.Entries;
|
||||
using Artemis.UI.Screens.Workshop.Parameters;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Builders;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using Avalonia.Threading;
|
||||
using DryIoc.ImTools;
|
||||
using DynamicData;
|
||||
using ReactiveUI;
|
||||
using StrawberryShake;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Profile;
|
||||
|
||||
public class ProfileListViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopListParameters>, IWorkshopViewModel
|
||||
public class ProfileListViewModel : EntryListBaseViewModel
|
||||
{
|
||||
private readonly INotificationService _notificationService;
|
||||
private readonly Func<IGetEntries_Entries_Items, EntryListViewModel> _getEntryListViewModel;
|
||||
private readonly IWorkshopClient _workshopClient;
|
||||
private readonly ObservableAsPropertyHelper<bool> _showPagination;
|
||||
private readonly ObservableAsPropertyHelper<bool> _isLoading;
|
||||
private SourceList<IGetEntries_Entries_Items> _entries = new();
|
||||
private int _page;
|
||||
private int _loadedPage = -1;
|
||||
private int _totalPages = 1;
|
||||
private int _entriesPerPage = 10;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ProfileListViewModel(IWorkshopClient workshopClient,
|
||||
IRouter router,
|
||||
CategoriesViewModel categoriesViewModel,
|
||||
IRouter router,
|
||||
CategoriesViewModel categoriesViewModel,
|
||||
INotificationService notificationService,
|
||||
Func<IGetEntries_Entries_Items, EntryListViewModel> getEntryListViewModel)
|
||||
Func<IGetEntries_Entries_Items, EntryListItemViewModel> getEntryListViewModel)
|
||||
: base(workshopClient, router, categoriesViewModel, notificationService, getEntryListViewModel)
|
||||
{
|
||||
_workshopClient = workshopClient;
|
||||
_notificationService = notificationService;
|
||||
_getEntryListViewModel = getEntryListViewModel;
|
||||
_showPagination = this.WhenAnyValue(vm => vm.TotalPages).Select(t => t > 1).ToProperty(this, vm => vm.ShowPagination);
|
||||
_isLoading = this.WhenAnyValue(vm => vm.Page, vm => vm.LoadedPage, (p, c) => p != c).ToProperty(this, vm => vm.IsLoading);
|
||||
}
|
||||
|
||||
CategoriesViewModel = categoriesViewModel;
|
||||
|
||||
_entries.Connect()
|
||||
.ObserveOn(new AvaloniaSynchronizationContext(DispatcherPriority.SystemIdle))
|
||||
.Transform(getEntryListViewModel)
|
||||
.Bind(out ReadOnlyObservableCollection<EntryListViewModel> entries)
|
||||
.Subscribe();
|
||||
Entries = entries;
|
||||
|
||||
// Respond to page changes
|
||||
this.WhenAnyValue(vm => vm.Page).Skip(1).Subscribe(p => Task.Run(() => router.Navigate($"workshop/profiles/{p}")));
|
||||
|
||||
// Respond to filter changes
|
||||
this.WhenActivated(d => CategoriesViewModel.WhenAnyValue(vm => vm.CategoryFilters).Skip(1).Subscribe(_ =>
|
||||
#region Overrides of EntryListBaseViewModel
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string GetPagePath(int page)
|
||||
{
|
||||
return $"workshop/profiles/{page}";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override EntryFilterInput GetFilter()
|
||||
{
|
||||
return new EntryFilterInput
|
||||
{
|
||||
// Reset to page one, will trigger a query
|
||||
if (Page != 1)
|
||||
Page = 1;
|
||||
// If already at page one, force a query
|
||||
else
|
||||
Task.Run(() => Query(CancellationToken.None));
|
||||
}).DisposeWith(d));
|
||||
}
|
||||
|
||||
public bool ShowPagination => _showPagination.Value;
|
||||
public bool IsLoading => _isLoading.Value;
|
||||
|
||||
public CategoriesViewModel CategoriesViewModel { get; }
|
||||
|
||||
public ReadOnlyObservableCollection<EntryListViewModel> 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 int EntriesPerPage
|
||||
{
|
||||
get => _entriesPerPage;
|
||||
set => RaiseAndSetIfChanged(ref _entriesPerPage, value);
|
||||
}
|
||||
|
||||
public override async Task OnNavigating(WorkshopListParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
Page = Math.Max(1, parameters.Page);
|
||||
|
||||
// Throttle page changes, wait longer for the first one to keep UI smooth
|
||||
// if (Entries == null)
|
||||
// await Task.Delay(400, cancellationToken);
|
||||
// else
|
||||
await Task.Delay(200, cancellationToken);
|
||||
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
await Query(cancellationToken);
|
||||
}
|
||||
|
||||
private async Task Query(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
EntryFilterInput filter = GetFilter();
|
||||
IOperationResult<IGetEntriesResult> entries = await _workshopClient.GetEntries.ExecuteAsync(filter, EntriesPerPage * (Page - 1), EntriesPerPage, cancellationToken);
|
||||
entries.EnsureNoErrors();
|
||||
|
||||
if (entries.Data?.Entries?.Items != null)
|
||||
And = new[]
|
||||
{
|
||||
TotalPages = (int) Math.Ceiling(entries.Data.Entries.TotalCount / (double) EntriesPerPage);
|
||||
_entries.Edit(e =>
|
||||
{
|
||||
e.Clear();
|
||||
e.AddRange(entries.Data.Entries.Items);
|
||||
});
|
||||
new EntryFilterInput {EntryType = new EntryTypeOperationFilterInput {Eq = WebClient.Workshop.EntryType.Profile}},
|
||||
base.GetFilter()
|
||||
}
|
||||
else
|
||||
TotalPages = 1;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_notificationService.CreateNotification()
|
||||
.WithTitle("Failed to load entries")
|
||||
.WithMessage(e.Message)
|
||||
.WithSeverity(NotificationSeverity.Error)
|
||||
.Show();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoadedPage = Page;
|
||||
}
|
||||
}
|
||||
|
||||
private EntryFilterInput GetFilter()
|
||||
{
|
||||
EntryFilterInput filter = new()
|
||||
{
|
||||
EntryType = new EntryTypeOperationFilterInput {Eq = WebClient.Workshop.EntryType.Profile},
|
||||
And = CategoriesViewModel.CategoryFilters
|
||||
};
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
public EntryType? EntryType => null;
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user