mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Submission wizard - Upload entry icon
Entry lists - Show entry icon
This commit is contained in:
1 parent
6014bb9e3c
commit
176a28761f
11 files changed
+214
-39
No files matched your search
@@ -23,8 +23,9 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0 0 10 0"
|
||||
Width="80"
|
||||
Height="80">
|
||||
<avalonia:MaterialIcon Kind="HandOkay" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="70" Height="70" />
|
||||
Height="80"
|
||||
ClipToBounds="True">
|
||||
<Image Source="{CompiledBinding EntryIcon^}" Stretch="UniformToFill"/>
|
||||
</Border>
|
||||
|
||||
<!-- Body -->
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
using Avalonia.Media.Imaging;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Entries;
|
||||
|
||||
public class EntryListViewModel : ViewModelBase
|
||||
public class EntryListViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IRouter _router;
|
||||
private readonly ObservableAsPropertyHelper<Bitmap?> _entryIcon;
|
||||
|
||||
public EntryListViewModel(IGetEntries_Entries_Items entry, IRouter router)
|
||||
public EntryListViewModel(IGetEntries_Entries_Items entry, IRouter router, IWorkshopService workshopService)
|
||||
{
|
||||
_router = router;
|
||||
|
||||
Entry = entry;
|
||||
EntryIcon = workshopService.GetEntryIcon(entry.Id, CancellationToken.None);
|
||||
NavigateToEntry = ReactiveCommand.CreateFromTask(ExecuteNavigateToEntry);
|
||||
}
|
||||
|
||||
public IGetEntries_Entries_Items Entry { get; }
|
||||
public ReactiveCommand<Unit,Unit> NavigateToEntry { get; }
|
||||
public Task<Bitmap?> EntryIcon { get; }
|
||||
public ReactiveCommand<Unit, Unit> NavigateToEntry { get; }
|
||||
|
||||
private async Task ExecuteNavigateToEntry()
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Builders;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using DryIoc.ImTools;
|
||||
using ReactiveUI;
|
||||
using StrawberryShake;
|
||||
|
||||
@@ -20,8 +21,8 @@ namespace Artemis.UI.Screens.Workshop.Profile;
|
||||
|
||||
public class ProfileListViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopListParameters>, IWorkshopViewModel
|
||||
{
|
||||
private readonly IRouter _router;
|
||||
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;
|
||||
@@ -31,18 +32,22 @@ public class ProfileListViewModel : RoutableScreen<ActivatableViewModelBase, Wor
|
||||
private int _totalPages = 1;
|
||||
private int _entriesPerPage = 10;
|
||||
|
||||
public ProfileListViewModel(IWorkshopClient workshopClient, IRouter router, CategoriesViewModel categoriesViewModel, INotificationService notificationService)
|
||||
public ProfileListViewModel(IWorkshopClient workshopClient,
|
||||
IRouter router,
|
||||
CategoriesViewModel categoriesViewModel,
|
||||
INotificationService notificationService,
|
||||
Func<IGetEntries_Entries_Items, EntryListViewModel> getEntryListViewModel)
|
||||
{
|
||||
_workshopClient = workshopClient;
|
||||
_router = router;
|
||||
_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;
|
||||
|
||||
// Respond to page changes
|
||||
this.WhenAnyValue(vm => vm.Page).Skip(1).Subscribe(p => Task.Run(() => _router.Navigate($"workshop/profiles/{p}")));
|
||||
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(_ =>
|
||||
{
|
||||
@@ -57,7 +62,7 @@ public class ProfileListViewModel : RoutableScreen<ActivatableViewModelBase, Wor
|
||||
|
||||
public bool ShowPagination => _showPagination.Value;
|
||||
public bool IsLoading => _isLoading.Value;
|
||||
|
||||
|
||||
public CategoriesViewModel CategoriesViewModel { get; }
|
||||
|
||||
public List<EntryListViewModel>? Entries
|
||||
@@ -108,10 +113,10 @@ public class ProfileListViewModel : RoutableScreen<ActivatableViewModelBase, Wor
|
||||
EntryFilterInput filter = GetFilter();
|
||||
IOperationResult<IGetEntriesResult> entries = await _workshopClient.GetEntries.ExecuteAsync(filter, EntriesPerPage * (Page - 1), EntriesPerPage, cancellationToken);
|
||||
entries.EnsureNoErrors();
|
||||
|
||||
|
||||
if (entries.Data?.Entries?.Items != null)
|
||||
{
|
||||
Entries = entries.Data.Entries.Items.Select(n => new EntryListViewModel(n, _router)).ToList();
|
||||
Entries = entries.Data.Entries.Items.Select(n => _getEntryListViewModel(n)).ToList();
|
||||
TotalPages = (int) Math.Ceiling(entries.Data.Entries.TotalCount / (double) EntriesPerPage);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -13,12 +13,14 @@ using Artemis.Core;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using System;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
|
||||
public class UploadStepViewModel : SubmissionViewModel
|
||||
{
|
||||
private readonly IWorkshopClient _workshopClient;
|
||||
private readonly IWorkshopService _workshopService;
|
||||
private readonly EntryUploadHandlerFactory _entryUploadHandlerFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly IRouter _router;
|
||||
@@ -30,9 +32,10 @@ public class UploadStepViewModel : SubmissionViewModel
|
||||
private Guid? _entryId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public UploadStepViewModel(IWorkshopClient workshopClient, EntryUploadHandlerFactory entryUploadHandlerFactory, IWindowService windowService, IRouter router)
|
||||
public UploadStepViewModel(IWorkshopClient workshopClient, IWorkshopService workshopService, EntryUploadHandlerFactory entryUploadHandlerFactory, IWindowService windowService, IRouter router)
|
||||
{
|
||||
_workshopClient = workshopClient;
|
||||
_workshopService = workshopService;
|
||||
_entryUploadHandlerFactory = entryUploadHandlerFactory;
|
||||
_windowService = windowService;
|
||||
_router = router;
|
||||
@@ -87,6 +90,10 @@ public class UploadStepViewModel : SubmissionViewModel
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
// Upload image
|
||||
if (State.Icon != null)
|
||||
await _workshopService.SetEntryIcon(entryId.Value, _progress, State.Icon, cancellationToken);
|
||||
|
||||
// Create the workshop entry
|
||||
try
|
||||
|
||||
Reference in new issue
Block a user