ModListGallery loading error display

This commit is contained in:
Justin Swanson 2020-01-18 22:37:21 -06:00
parent dbce33fb45
commit b5edd9ce26
3 changed files with 41 additions and 4 deletions

View File

@ -10,6 +10,8 @@ using System.Threading.Tasks;
using DynamicData;
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
@ -23,6 +25,9 @@ namespace Wabbajack
private int missingHashFallbackCounter;
[Reactive]
public IErrorResponse Error { get; set; }
public ModListGalleryVM(MainWindowVM mainWindowVM)
: base(mainWindowVM)
{
@ -32,8 +37,18 @@ namespace Wabbajack
.ObserveOn(RxApp.TaskpoolScheduler)
.SelectTask(async _ =>
{
return (await ModlistMetadata.LoadFromGithub())
.AsObservableChangeSet(x => x.DownloadMetadata?.Hash ?? $"Fallback{missingHashFallbackCounter++}");
try
{
Error = null;
var list = await ModlistMetadata.LoadFromGithub();
return list.AsObservableChangeSet(x => x.DownloadMetadata?.Hash ?? $"Fallback{missingHashFallbackCounter++}");
}
catch (Exception ex)
{
Utils.Error(ex);
Error = ErrorResponse.Fail(ex);
return Observable.Empty<IChangeSet<ModlistMetadata, string>>();
}
})
// Unsubscribe and release when not active
.FlowSwitch(

View File

@ -52,6 +52,16 @@
</ScrollViewer>
</Border>
<mahapps:ProgressRing x:Name="LoadingRing" Grid.Row="1" />
<iconPacks:PackIconControl
x:Name="ErrorIcon"
Grid.Row="1"
Width="55"
Height="55"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{StaticResource ErrorBrush}"
Kind="{x:Static iconPacks:PackIconMaterialKind.AlertCircle}"
ToolTip="Error loading modlist gallery" />
<local:TopProgressView
Title="Browsing Modlists"
Grid.Row="0"

View File

@ -23,10 +23,22 @@ namespace Wabbajack
this.WhenAny(x => x.ViewModel.ModLists)
.BindToStrict(this, x => x.ModListGalleryControl.ItemsSource)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.ModLists.Count)
.Select(x => x > 0 ? Visibility.Collapsed : Visibility.Visible)
Observable.CombineLatest(
this.WhenAny(x => x.ViewModel.ModLists.Count)
.Select(x => x > 0),
this.WhenAny(x => x.ViewModel.Error)
.Select(e => e?.Succeeded ?? true),
resultSelector: (hasContent, succeeded) =>
{
return !hasContent && succeeded;
})
.Select(x => x ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, x => x.LoadingRing.Visibility)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Error)
.Select(e => (e?.Succeeded ?? true) ? Visibility.Collapsed : Visibility.Visible)
.BindToStrict(this, x => x.ErrorIcon.Visibility)
.DisposeWith(dispose);
});
}
}