Shared UI - Added HttpClientUtilities offering progressable stream content

Submission wizard - Added upload progress
Submission wizard - Close on finish
This commit is contained in:
Robert committed 2023-08-14 20:10:13 +02:00
1 parent ad4da3032d
commit a1fd8d5099
10 files changed
+249 -16

No files matched your search

@@ -26,7 +26,7 @@ public class WorkshopHomeViewModel : ActivatableViewModelBase, IWorkshopViewMode
private async Task ExecuteAddSubmission(CancellationToken arg)
{
await _windowService.ShowDialogAsync<SubmissionWizardViewModel>();
await _windowService.ShowDialogAsync<SubmissionWizardViewModel, bool>();
}
public EntryType? EntryType => null;
@@ -21,6 +21,12 @@
<TextBlock TextAlignment="Center" TextWrapping="Wrap">
Wooo, the final step, that was pretty easy, right!?
</TextBlock>
<ProgressBar Margin="0 15 0 0"
Width="380"
IsVisible="{CompiledBinding !Finished}"
IsIndeterminate="{CompiledBinding ProgressIndeterminate}"
Value="{CompiledBinding ProgressPercentage}"></ProgressBar>
<StackPanel IsVisible="{CompiledBinding Finished}" Margin="0 100 0 0">
<Lottie Path="/Assets/Animations/success.json" RepeatCount="1" Width="300" Height="300"></Lottie>
@@ -10,6 +10,9 @@ using ReactiveUI;
using StrawberryShake;
using System.Reactive.Disposables;
using Artemis.Core;
using Artemis.UI.Shared.Routing;
using System;
using Artemis.UI.Shared.Utilities;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
@@ -18,19 +21,33 @@ public class UploadStepViewModel : SubmissionViewModel
private readonly IWorkshopClient _workshopClient;
private readonly EntryUploadHandlerFactory _entryUploadHandlerFactory;
private readonly IWindowService _windowService;
private readonly IRouter _router;
private readonly Progress<StreamProgress> _progress = new();
private readonly ObservableAsPropertyHelper<int> _progressPercentage;
private readonly ObservableAsPropertyHelper<bool> _progressIndeterminate;
private bool _finished;
private Guid? _entryId;
/// <inheritdoc />
public UploadStepViewModel(IWorkshopClient workshopClient, EntryUploadHandlerFactory entryUploadHandlerFactory, IWindowService windowService)
public UploadStepViewModel(IWorkshopClient workshopClient, EntryUploadHandlerFactory entryUploadHandlerFactory, IWindowService windowService, IRouter router)
{
_workshopClient = workshopClient;
_entryUploadHandlerFactory = entryUploadHandlerFactory;
_windowService = windowService;
_router = router;
ShowGoBack = false;
ContinueText = "Finish";
Continue = ReactiveCommand.Create(ExecuteContinue, this.WhenAnyValue(vm => vm.Finished));
Continue = ReactiveCommand.CreateFromTask(ExecuteContinue, this.WhenAnyValue(vm => vm.Finished));
_progressPercentage = Observable.FromEventPattern<StreamProgress>(x => _progress.ProgressChanged += x, x => _progress.ProgressChanged -= x)
.Select(e => e.EventArgs.ProgressPercentage)
.ToProperty(this, vm => vm.ProgressPercentage);
_progressIndeterminate = Observable.FromEventPattern<StreamProgress>(x => _progress.ProgressChanged += x, x => _progress.ProgressChanged -= x)
.Select(e => e.EventArgs.ProgressPercentage == 0)
.ToProperty(this, vm => vm.ProgressIndeterminate);
this.WhenActivated(d => Observable.FromAsync(ExecuteUpload).Subscribe().DisposeWith(d));
}
@@ -40,6 +57,9 @@ public class UploadStepViewModel : SubmissionViewModel
/// <inheritdoc />
public override ReactiveCommand<Unit, Unit> GoBack { get; } = null!;
public int ProgressPercentage => _progressPercentage.Value;
public bool ProgressIndeterminate => _progressIndeterminate.Value;
public bool Finished
{
get => _finished;
@@ -72,7 +92,7 @@ public class UploadStepViewModel : SubmissionViewModel
try
{
IEntryUploadHandler uploadHandler = _entryUploadHandlerFactory.CreateHandler(State.EntryType);
EntryUploadResult uploadResult = await uploadHandler.CreateReleaseAsync(entryId.Value, State.EntrySource!, cancellationToken);
EntryUploadResult uploadResult = await uploadHandler.CreateReleaseAsync(entryId.Value, State.EntrySource!, _progress, cancellationToken);
if (!uploadResult.IsSuccess)
{
string? message = uploadResult.Message;
@@ -85,6 +105,7 @@ public class UploadStepViewModel : SubmissionViewModel
return;
}
_entryId = entryId;
Finished = true;
}
catch (Exception e)
@@ -94,8 +115,25 @@ public class UploadStepViewModel : SubmissionViewModel
}
}
private void ExecuteContinue()
private async Task ExecuteContinue()
{
throw new NotImplementedException();
if (_entryId == null)
return;
State.Finish();
switch (State.EntryType)
{
case EntryType.Layout:
await _router.Navigate($"workshop/layouts/{_entryId.Value}");
break;
case EntryType.Plugin:
await _router.Navigate($"workshop/plugins/{_entryId.Value}");
break;
case EntryType.Profile:
await _router.Navigate($"workshop/profiles/{_entryId.Value}");
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
@@ -44,4 +44,14 @@ public class SubmissionWizardState
_windowService.ShowExceptionDialog("Wizard screen failed to activate", e);
}
}
public void Finish()
{
_wizardViewModel.Close(true);
}
public void Cancel()
{
_wizardViewModel.Close(false);
}
}