Merge pull request #402 from Noggog/modlist-error-display

Modlist Gallery Error Display
This commit is contained in:
Timothy Baldridge 2020-01-21 05:49:16 -07:00 committed by GitHub
commit ddbfaafdb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 10 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

@ -166,7 +166,9 @@ namespace Wabbajack
}
});
await Metrics.Send(Metrics.Downloading, Metadata.Title);
Task.Run(() => Metrics.Send(Metrics.Downloading, Metadata.Title))
.FireAndForget(ex => Utils.Error(ex, "Error sending download metric"));
return await tcs.Task;
}

View File

@ -32,7 +32,7 @@
<local:ModeSelectionView />
</DataTemplate>
<DataTemplate DataType="{x:Type local:ModListGalleryVM}">
<local:ModListGalleryView />
<local:ModListGalleryView ViewModel="{Binding}" />
</DataTemplate>
<DataTemplate DataType="{x:Type local:WebBrowserVM}">
<local:WebBrowserView />

View File

@ -1,14 +1,17 @@
<UserControl
<rxui:ReactiveUserControl
x:Class="Wabbajack.ModListGalleryView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:local="clr-namespace:Wabbajack"
xmlns:mahapps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:rxui="http://reactiveui.net"
xmlns:system="clr-namespace:System;assembly=mscorlib"
d:DesignHeight="450"
d:DesignWidth="800"
x:TypeArguments="local:ModListGalleryVM"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
@ -32,9 +35,9 @@
BorderThickness="1,0,1,1">
<ScrollViewer Background="Transparent" VerticalScrollBarVisibility="Auto">
<ItemsControl
x:Name="ModListGalleryControl"
Margin="0,10,0,0"
HorizontalAlignment="Center"
ItemsSource="{Binding ModLists}">
HorizontalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
@ -48,6 +51,17 @@
</ItemsControl>
</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"
@ -61,10 +75,9 @@
Margin="7,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Command="{Binding BackCommand}"
Style="{StaticResource IconCircleButtonStyle}"
ToolTip="Back to main menu">
<iconPacks:PackIconMaterial Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}" Kind="ArrowLeft" />
</Button>
</Grid>
</UserControl>
</rxui:ReactiveUserControl>

View File

@ -1,16 +1,45 @@
using System.Diagnostics;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Controls;
using MahApps.Metro.Controls;
using ReactiveUI;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack
{
public partial class ModListGalleryView : UserControl
public partial class ModListGalleryView : ReactiveUserControl<ModListGalleryVM>
{
public ModListGalleryView()
{
InitializeComponent();
this.WhenActivated(dispose =>
{
this.WhenAny(x => x.ViewModel.BackCommand)
.BindToStrict(this, x => x.BackButton.Command)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.ModLists)
.BindToStrict(this, x => x.ModListGalleryControl.ItemsSource)
.DisposeWith(dispose);
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);
});
}
}
}