mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Workshop Library - Added library pages
UI - Tweaked design to more closely match WinUI 3 gallery examples
This commit is contained in:
parent
e545d2f3da
commit
9c6d7329a6
@ -23,15 +23,11 @@
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Design.PreviewWith>
|
||||
|
||||
<Styles.Resources>
|
||||
<CornerRadius x:Key="CardCornerRadius">8</CornerRadius>
|
||||
</Styles.Resources>
|
||||
|
||||
|
||||
<!-- Add Styles Here -->
|
||||
<Style Selector="Border.router-container">
|
||||
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource NavigationViewContentBackground}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource NavigationViewContentGridBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="CornerRadius" Value="8 0 0 0" />
|
||||
<Setter Property="ClipToBounds" Value="True" />
|
||||
@ -39,18 +35,18 @@
|
||||
|
||||
<Style Selector="Border.card">
|
||||
<Setter Property="Padding" Value="16" />
|
||||
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource NavigationViewContentBackground}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource NavigationViewContentGridBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource CardCornerRadius}" />
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.card-condensed">
|
||||
<Setter Property="Padding" Value="8" />
|
||||
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource NavigationViewContentBackground}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource NavigationViewContentGridBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource CardCornerRadius}" />
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.card-separator">
|
||||
|
||||
1
src/Artemis.UI/Assets/Animations/empty.json
Normal file
1
src/Artemis.UI/Assets/Animations/empty.json
Normal file
File diff suppressed because one or more lines are too long
15
src/Artemis.UI/Extensions/IActivatableViewModelExtensions.cs
Normal file
15
src/Artemis.UI/Extensions/IActivatableViewModelExtensions.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Extensions;
|
||||
|
||||
public static class ActivatableViewModelExtensions
|
||||
{
|
||||
public static void WhenActivatedAsync(this IActivatableViewModel item, Func<CompositeDisposable, Task> block)
|
||||
{
|
||||
item.WhenActivated(d => Dispatcher.UIThread.InvokeAsync(async () => await block(d)));
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ public static class Routes
|
||||
{
|
||||
new RouteRegistration<BlankViewModel>("blank"),
|
||||
new RouteRegistration<HomeViewModel>("home"),
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
new RouteRegistration<WorkshopViewModel>("workshop")
|
||||
{
|
||||
Children = new List<IRouterRegistration>()
|
||||
@ -31,14 +31,17 @@ public static class Routes
|
||||
new RouteRegistration<ProfileDetailsViewModel>("profiles/{entryId:guid}"),
|
||||
new RouteRegistration<LayoutListViewModel>("layouts/{page:int}"),
|
||||
new RouteRegistration<LayoutDetailsViewModel>("layouts/{entryId:guid}"),
|
||||
new RouteRegistration<WorkshopLibraryViewModel>("library") {Children = new List<IRouterRegistration>()
|
||||
new RouteRegistration<WorkshopLibraryViewModel>("library")
|
||||
{
|
||||
new RouteRegistration<LibraryInstalledViewModel>("installed"),
|
||||
new RouteRegistration<LibrarySubmissionsViewModel>("submissions"),
|
||||
}}
|
||||
Children = new List<IRouterRegistration>()
|
||||
{
|
||||
new RouteRegistration<LibraryInstalledViewModel>("installed"),
|
||||
new RouteRegistration<LibrarySubmissionsViewModel>("submissions"),
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
#endif
|
||||
#endif
|
||||
new RouteRegistration<SurfaceEditorViewModel>("surface-editor"),
|
||||
new RouteRegistration<SettingsViewModel>("settings")
|
||||
{
|
||||
|
||||
@ -43,6 +43,7 @@ public class SidebarViewModel : ActivatableViewModelBase
|
||||
{
|
||||
new(MaterialIconKind.FolderVideo, "Profiles", "workshop/profiles/1", "workshop/profiles"),
|
||||
new(MaterialIconKind.KeyboardVariant, "Layouts", "workshop/layouts/1", "workshop/layouts"),
|
||||
new(MaterialIconKind.Bookshelf, "Library", "workshop/library"),
|
||||
}),
|
||||
#endif
|
||||
new(MaterialIconKind.Devices, "Surface Editor", "surface-editor"),
|
||||
|
||||
@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
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.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 DynamicData;
|
||||
using ReactiveUI;
|
||||
using StrawberryShake;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Entries;
|
||||
|
||||
public abstract class EntryListBaseViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopListParameters>, IWorkshopViewModel
|
||||
{
|
||||
private readonly INotificationService _notificationService;
|
||||
private readonly IWorkshopClient _workshopClient;
|
||||
private readonly ObservableAsPropertyHelper<bool> _showPagination;
|
||||
private readonly ObservableAsPropertyHelper<bool> _isLoading;
|
||||
private readonly SourceList<IGetEntries_Entries_Items> _entries = new();
|
||||
|
||||
private int _page;
|
||||
private int _loadedPage = -1;
|
||||
private int _totalPages = 1;
|
||||
private int _entriesPerPage = 10;
|
||||
|
||||
protected EntryListBaseViewModel(IWorkshopClient workshopClient, IRouter router, CategoriesViewModel categoriesViewModel, INotificationService notificationService,
|
||||
Func<IGetEntries_Entries_Items, EntryListItemViewModel> getEntryListViewModel)
|
||||
{
|
||||
_workshopClient = workshopClient;
|
||||
_notificationService = notificationService;
|
||||
_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<EntryListItemViewModel> entries)
|
||||
.Subscribe();
|
||||
Entries = entries;
|
||||
|
||||
// Respond to page changes
|
||||
this.WhenAnyValue(vm => vm.Page).Skip(1).Subscribe(p => Task.Run(() => router.Navigate(GetPagePath(p))));
|
||||
|
||||
// Respond to filter changes
|
||||
this.WhenActivated(d => CategoriesViewModel.WhenAnyValue(vm => vm.CategoryFilters).Skip(1).Subscribe(_ =>
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
|
||||
protected abstract string GetPagePath(int page);
|
||||
|
||||
public bool ShowPagination => _showPagination.Value;
|
||||
public bool IsLoading => _isLoading.Value;
|
||||
|
||||
public CategoriesViewModel CategoriesViewModel { get; }
|
||||
|
||||
public ReadOnlyObservableCollection<EntryListItemViewModel> 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);
|
||||
|
||||
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)
|
||||
{
|
||||
TotalPages = (int) Math.Ceiling(entries.Data.Entries.TotalCount / (double) EntriesPerPage);
|
||||
_entries.Edit(e =>
|
||||
{
|
||||
e.Clear();
|
||||
e.AddRange(entries.Data.Entries.Items);
|
||||
});
|
||||
}
|
||||
else
|
||||
TotalPages = 1;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_notificationService.CreateNotification()
|
||||
.WithTitle("Failed to load entries")
|
||||
.WithMessage(e.Message)
|
||||
.WithSeverity(NotificationSeverity.Error)
|
||||
.Show();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoadedPage = Page;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual EntryFilterInput GetFilter()
|
||||
{
|
||||
return new EntryFilterInput {And = CategoriesViewModel.CategoryFilters};
|
||||
}
|
||||
|
||||
public EntryType? EntryType => null;
|
||||
}
|
||||
@ -7,16 +7,15 @@
|
||||
xmlns:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="110"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Entries.EntryListView"
|
||||
x:DataType="entries1:EntryListViewModel">
|
||||
x:Class="Artemis.UI.Screens.Workshop.Entries.EntryListItemView"
|
||||
x:DataType="entries1:EntryListItemViewModel">
|
||||
<UserControl.Resources>
|
||||
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
|
||||
<converters:DateTimeConverter x:Key="DateTimeConverter" />
|
||||
</UserControl.Resources>
|
||||
<Button MinHeight="110"
|
||||
MaxHeight="140"
|
||||
Padding="16"
|
||||
CornerRadius="8"
|
||||
Padding="12"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Command="{CompiledBinding NavigateToEntry}"
|
||||
@ -24,8 +23,7 @@
|
||||
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||
<!-- Icon -->
|
||||
<Border Grid.Column="0"
|
||||
CornerRadius="12"
|
||||
Background="{StaticResource ControlStrokeColorOnAccentDefault}"
|
||||
CornerRadius="6"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0 0 10 0"
|
||||
Width="80"
|
||||
@ -2,9 +2,9 @@ using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Entries;
|
||||
|
||||
public partial class EntryListView : ReactiveUserControl<EntryListViewModel>
|
||||
public partial class EntryListItemView : ReactiveUserControl<EntryListItemViewModel>
|
||||
{
|
||||
public EntryListView()
|
||||
public EntryListItemView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@ -13,11 +13,11 @@ using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Entries;
|
||||
|
||||
public class EntryListViewModel : ActivatableViewModelBase
|
||||
public class EntryListItemViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IRouter _router;
|
||||
|
||||
public EntryListViewModel(IGetEntries_Entries_Items entry, IRouter router)
|
||||
public EntryListItemViewModel(IGetEntries_Entries_Items entry, IRouter router)
|
||||
{
|
||||
_router = router;
|
||||
|
||||
@ -2,6 +2,7 @@ using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
@ -27,7 +28,7 @@ public class WorkshopHomeViewModel : ActivatableViewModelBase, IWorkshopViewMode
|
||||
AddSubmission = ReactiveCommand.CreateFromTask(ExecuteAddSubmission, this.WhenAnyValue(vm => vm.WorkshopReachable));
|
||||
Navigate = ReactiveCommand.CreateFromTask<string>(async r => await router.Navigate(r), this.WhenAnyValue(vm => vm.WorkshopReachable));
|
||||
|
||||
this.WhenActivated((CompositeDisposable _) => Dispatcher.UIThread.InvokeAsync(ValidateWorkshopStatus));
|
||||
this.WhenActivatedAsync(async d => WorkshopReachable = await workshopService.ValidateWorkshopStatus(d.AsCancellationToken()));
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> AddSubmission { get; }
|
||||
@ -44,10 +45,5 @@ public class WorkshopHomeViewModel : ActivatableViewModelBase, IWorkshopViewMode
|
||||
await _windowService.ShowDialogAsync<SubmissionWizardViewModel, bool>();
|
||||
}
|
||||
|
||||
private async Task ValidateWorkshopStatus()
|
||||
{
|
||||
WorkshopReachable = await _workshopService.ValidateWorkshopStatus();
|
||||
}
|
||||
|
||||
public EntryType? EntryType => null;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
using System.Net;
|
||||
|
||||
using System.Reactive;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -41,7 +41,7 @@ public class WorkshopOfflineViewModel : RoutableScreen<ActivatableViewModelBase,
|
||||
|
||||
private async Task ExecuteRetry(CancellationToken cancellationToken)
|
||||
{
|
||||
IWorkshopService.WorkshopStatus status = await _workshopService.GetWorkshopStatus();
|
||||
IWorkshopService.WorkshopStatus status = await _workshopService.GetWorkshopStatus(cancellationToken);
|
||||
if (status.IsReachable)
|
||||
await _router.Navigate("workshop");
|
||||
|
||||
|
||||
@ -3,23 +3,40 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:layout="clr-namespace:Artemis.UI.Screens.Workshop.Layout"
|
||||
xmlns:pagination="clr-namespace:Artemis.UI.Shared.Pagination;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Layout.LayoutListView"
|
||||
x:DataType="layout:LayoutListViewModel">
|
||||
<Border Classes="router-container">
|
||||
<Grid ColumnDefinitions="300,*" Margin="10">
|
||||
<Border Classes="card-condensed" Grid.Column="0" Margin="0 0 10 0">
|
||||
<StackPanel>
|
||||
<TextBlock Classes="h3">Categories</TextBlock>
|
||||
<ContentControl Content="{CompiledBinding CategoriesViewModel}"></ContentControl>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Grid ColumnDefinitions="300,*" Margin="10" RowDefinitions="*,Auto">
|
||||
<StackPanel Grid.Column="0" Grid.RowSpan="2" Margin="0 0 10 0" VerticalAlignment="Top">
|
||||
<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 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>
|
||||
<ContentControl Content="{CompiledBinding}" Margin="0 0 0 5"></ContentControl>
|
||||
</DataTemplate>
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
</ItemsRepeater>
|
||||
</ScrollViewer>
|
||||
|
||||
<Border Classes="card-condensed" Grid.Column="1">
|
||||
<TextBlock>
|
||||
<Run Text="Layout list main panel, page: " /><Run Text="{CompiledBinding Page}"></Run>
|
||||
</TextBlock>
|
||||
</Border>
|
||||
<pagination:Pagination Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
Margin="0 20 0 10"
|
||||
IsVisible="{CompiledBinding ShowPagination}"
|
||||
Value="{CompiledBinding Page}"
|
||||
Maximum="{CompiledBinding TotalPages}"
|
||||
HorizontalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@ -1,36 +1,44 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Screens.Workshop.Categories;
|
||||
using Artemis.UI.Screens.Workshop.Parameters;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Screens.Workshop.Entries;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.WebClient.Workshop;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Layout;
|
||||
|
||||
public class LayoutListViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopListParameters>, IWorkshopViewModel
|
||||
public class LayoutListViewModel : EntryListBaseViewModel
|
||||
{
|
||||
private int _page;
|
||||
|
||||
public LayoutListViewModel(CategoriesViewModel categoriesViewModel)
|
||||
/// <inheritdoc />
|
||||
public LayoutListViewModel(IWorkshopClient workshopClient,
|
||||
IRouter router,
|
||||
CategoriesViewModel categoriesViewModel,
|
||||
INotificationService notificationService,
|
||||
Func<IGetEntries_Entries_Items, EntryListItemViewModel> getEntryListViewModel)
|
||||
: base(workshopClient, router, categoriesViewModel, notificationService, getEntryListViewModel)
|
||||
{
|
||||
CategoriesViewModel = categoriesViewModel;
|
||||
}
|
||||
|
||||
public CategoriesViewModel CategoriesViewModel { get; }
|
||||
#region Overrides of EntryListBaseViewModel
|
||||
|
||||
public int Page
|
||||
/// <inheritdoc />
|
||||
protected override string GetPagePath(int page)
|
||||
{
|
||||
get => _page;
|
||||
set => RaiseAndSetIfChanged(ref _page, value);
|
||||
return $"workshop/layouts/{page}";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override EntryFilterInput GetFilter()
|
||||
{
|
||||
return new EntryFilterInput
|
||||
{
|
||||
And = new[]
|
||||
{
|
||||
new EntryFilterInput {EntryType = new EntryTypeOperationFilterInput {Eq = WebClient.Workshop.EntryType.Layout}},
|
||||
base.GetFilter()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override Task OnNavigating(WorkshopListParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
Page = Math.Max(1, parameters.Page);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public EntryType? EntryType => WebClient.Workshop.EntryType.Layout;
|
||||
#endregion
|
||||
}
|
||||
@ -2,7 +2,67 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Library.Tabs.LibrarySubmissionsView">
|
||||
Submission management here 😗
|
||||
</UserControl>
|
||||
xmlns:tabs="clr-namespace:Artemis.UI.Screens.Workshop.Library.Tabs"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:workshop="clr-namespace:Artemis.WebClient.Workshop;assembly=Artemis.WebClient.Workshop"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="650"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Library.Tabs.LibrarySubmissionsView"
|
||||
x:DataType="tabs:LibrarySubmissionsViewModel">
|
||||
<UserControl.Resources>
|
||||
<controls:SymbolIconSource x:Key="GoIcon" Symbol="ChevronRight" />
|
||||
</UserControl.Resources>
|
||||
|
||||
<UserControl.Styles>
|
||||
<Styles>
|
||||
<Style Selector="StackPanel.empty-state > TextBlock">
|
||||
<Setter Property="TextAlignment" Value="Center"></Setter>
|
||||
<Setter Property="TextWrapping" Value="Wrap"></Setter>
|
||||
</Style>
|
||||
</Styles>
|
||||
</UserControl.Styles>
|
||||
|
||||
<Panel IsVisible="{CompiledBinding !IsLoading}">
|
||||
<StackPanel IsVisible="{CompiledBinding !IsLoggedIn^}" Margin="0 50 0 0" Classes="empty-state">
|
||||
<TextBlock Theme="{StaticResource TitleTextBlockStyle}">You are not logged in</TextBlock>
|
||||
<TextBlock>
|
||||
<Run>In order to manage your submissions you must be logged in.</Run>
|
||||
</TextBlock>
|
||||
<Lottie Path="/Assets/Animations/login-pending.json" RepeatCount="1" Width="350" Height="350"></Lottie>
|
||||
<Button HorizontalAlignment="Center" Command="{CompiledBinding Login}">Log in</Button>
|
||||
</StackPanel>
|
||||
|
||||
<Panel IsVisible="{CompiledBinding IsLoggedIn^}">
|
||||
<StackPanel IsVisible="{CompiledBinding !Entries.Count}" Margin="0 50 0 0" Classes="empty-state">
|
||||
<TextBlock Theme="{StaticResource TitleTextBlockStyle}">Oh boy, it's empty here 🤔</TextBlock>
|
||||
<TextBlock>
|
||||
<Run>Any entries you submit to the workshop you can later manage here</Run>
|
||||
</TextBlock>
|
||||
<Lottie Path="/Assets/Animations/empty.json" RepeatCount="1" Width="350" Height="350"></Lottie>
|
||||
<Button HorizontalAlignment="Center" Command="{CompiledBinding AddSubmission}">Submit new entry</Button>
|
||||
</StackPanel>
|
||||
|
||||
<ItemsRepeater IsVisible="{CompiledBinding Entries.Count}" ItemsSource="{CompiledBinding Entries}">
|
||||
<ItemsRepeater.ItemTemplate>
|
||||
<DataTemplate DataType="workshop:IGetSubmittedEntries_SubmittedEntries">
|
||||
<controls:SettingsExpander
|
||||
Header="{CompiledBinding Name}"
|
||||
Description="{CompiledBinding Summary}"
|
||||
IsClickEnabled="True"
|
||||
ActionIconSource="{StaticResource GoIcon}"
|
||||
Command="{Binding $parent[tabs:LibrarySubmissionsView].DataContext.NavigateToEntry}"
|
||||
CommandParameter="{CompiledBinding}">
|
||||
<controls:SettingsExpander.FooterTemplate>
|
||||
<DataTemplate x:DataType="workshop:IGetSubmittedEntries_SubmittedEntries">
|
||||
<Border Classes="badge" VerticalAlignment="Top" Margin="0 5 0 0">
|
||||
<TextBlock Text="{CompiledBinding EntryType}"></TextBlock>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</controls:SettingsExpander.FooterTemplate>
|
||||
</controls:SettingsExpander>
|
||||
</DataTemplate>
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
</ItemsRepeater>
|
||||
</Panel>
|
||||
</Panel>
|
||||
|
||||
</UserControl>
|
||||
@ -1,8 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Screens.Workshop.CurrentUser;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
using DynamicData;
|
||||
using ReactiveUI;
|
||||
using StrawberryShake;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Library.Tabs;
|
||||
|
||||
public class LibrarySubmissionsViewModel : ActivatableViewModelBase
|
||||
public class LibrarySubmissionsViewModel : ActivatableViewModelBase, IWorkshopViewModel
|
||||
{
|
||||
|
||||
private readonly IWorkshopClient _client;
|
||||
private readonly SourceCache<IGetSubmittedEntries_SubmittedEntries, Guid> _entries;
|
||||
private readonly IWindowService _windowService;
|
||||
private bool _isLoading = true;
|
||||
private bool _workshopReachable;
|
||||
|
||||
public LibrarySubmissionsViewModel(IWorkshopClient client, IAuthenticationService authenticationService, IWindowService windowService, IWorkshopService workshopService, IRouter router)
|
||||
{
|
||||
_client = client;
|
||||
_windowService = windowService;
|
||||
_entries = new SourceCache<IGetSubmittedEntries_SubmittedEntries, Guid>(e => e.Id);
|
||||
_entries.Connect().Bind(out ReadOnlyObservableCollection<IGetSubmittedEntries_SubmittedEntries> entries).Subscribe();
|
||||
|
||||
AddSubmission = ReactiveCommand.CreateFromTask(ExecuteAddSubmission, this.WhenAnyValue(vm => vm.WorkshopReachable));
|
||||
Login = ReactiveCommand.CreateFromTask(ExecuteLogin, this.WhenAnyValue(vm => vm.WorkshopReachable));
|
||||
NavigateToEntry = ReactiveCommand.CreateFromTask<IGetSubmittedEntries_SubmittedEntries>(ExecuteNavigateToEntry);
|
||||
|
||||
IsLoggedIn = authenticationService.IsLoggedIn;
|
||||
Entries = entries;
|
||||
|
||||
this.WhenActivatedAsync(async d =>
|
||||
{
|
||||
WorkshopReachable = await workshopService.ValidateWorkshopStatus(d.AsCancellationToken());
|
||||
if (WorkshopReachable)
|
||||
await GetEntries(d.AsCancellationToken());
|
||||
});
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Login { get; }
|
||||
public ReactiveCommand<Unit, Unit> AddSubmission { get; }
|
||||
public ReactiveCommand<IGetSubmittedEntries_SubmittedEntries, Unit> NavigateToEntry { get; }
|
||||
|
||||
public IObservable<bool> IsLoggedIn { get; }
|
||||
public ReadOnlyObservableCollection<IGetSubmittedEntries_SubmittedEntries> Entries { get; }
|
||||
|
||||
public bool WorkshopReachable
|
||||
{
|
||||
get => _workshopReachable;
|
||||
set => RaiseAndSetIfChanged(ref _workshopReachable, value);
|
||||
}
|
||||
|
||||
public bool IsLoading
|
||||
{
|
||||
get => _isLoading;
|
||||
set => RaiseAndSetIfChanged(ref _isLoading, value);
|
||||
}
|
||||
|
||||
private async Task ExecuteLogin(CancellationToken ct)
|
||||
{
|
||||
await _windowService.CreateContentDialog().WithViewModel(out WorkshopLoginViewModel _).WithTitle("Workshop login").ShowAsync();
|
||||
}
|
||||
|
||||
private async Task ExecuteAddSubmission(CancellationToken arg)
|
||||
{
|
||||
await _windowService.ShowDialogAsync<SubmissionWizardViewModel, bool>();
|
||||
}
|
||||
|
||||
private Task ExecuteNavigateToEntry(IGetSubmittedEntries_SubmittedEntries entry, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task GetEntries(CancellationToken ct)
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
IOperationResult<IGetSubmittedEntriesResult> result = await _client.GetSubmittedEntries.ExecuteAsync(null, ct);
|
||||
|
||||
if (result.Data?.SubmittedEntries == null)
|
||||
_entries.Clear();
|
||||
else
|
||||
_entries.Edit(e =>
|
||||
{
|
||||
e.Clear();
|
||||
e.AddOrUpdate(result.Data.SubmittedEntries);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
public EntryType? EntryType => null;
|
||||
}
|
||||
@ -2,26 +2,25 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:library="clr-namespace:Artemis.UI.Screens.Workshop.Library"
|
||||
xmlns:routing="clr-namespace:Artemis.UI.Routing"
|
||||
xmlns:ui1="clr-namespace:Artemis.UI"
|
||||
xmlns:ui="clr-namespace:Artemis.UI"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Library.WorkshopLibraryView"
|
||||
x:DataType="library:WorkshopLibraryViewModel">
|
||||
<ui:NavigationView PaneDisplayMode="Top" MenuItemsSource="{CompiledBinding Tabs}" SelectedItem="{CompiledBinding SelectedTab}">
|
||||
<ui:NavigationView.Styles>
|
||||
<controls:NavigationView PaneDisplayMode="Top" MenuItemsSource="{CompiledBinding Tabs}" SelectedItem="{CompiledBinding SelectedTab}">
|
||||
<controls:NavigationView.Styles>
|
||||
<Styles>
|
||||
<Style Selector="ui|NavigationView:topnavminimal /template/ SplitView Border#ContentGridBorder">
|
||||
<Style Selector="controls|NavigationView:topnavminimal /template/ SplitView Border#ContentGridBorder">
|
||||
<Setter Property="CornerRadius" Value="8 0 0 0" />
|
||||
</Style>
|
||||
</Styles>
|
||||
</ui:NavigationView.Styles>
|
||||
</controls:NavigationView.Styles>
|
||||
|
||||
<ui:Frame Name="TabFrame" IsNavigationStackEnabled="False" CacheSize="0">
|
||||
<ui:Frame.NavigationPageFactory>
|
||||
<ui1:PageFactory/>
|
||||
</ui:Frame.NavigationPageFactory>
|
||||
</ui:Frame>
|
||||
</ui:NavigationView>
|
||||
<controls:Frame Name="TabFrame" IsNavigationStackEnabled="False" CacheSize="0" Padding="20">
|
||||
<controls:Frame.NavigationPageFactory>
|
||||
<ui:PageFactory/>
|
||||
</controls:Frame.NavigationPageFactory>
|
||||
</controls:Frame>
|
||||
</controls:NavigationView>
|
||||
</UserControl>
|
||||
|
||||
@ -21,17 +21,18 @@ public partial class WorkshopLibraryView : ReactiveUserControl<WorkshopLibraryVi
|
||||
|
||||
private void Navigate(ViewModelBase viewModel)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
if (ViewModel == null)
|
||||
return;
|
||||
|
||||
SlideNavigationTransitionInfo transitionInfo = new()
|
||||
{
|
||||
Effect = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab) > _lastIndex ? SlideNavigationTransitionEffect.FromRight : SlideNavigationTransitionEffect.FromLeft
|
||||
};
|
||||
TabFrame.NavigateFromObject(viewModel, new FrameNavigationOptions {TransitionInfoOverride = transitionInfo});
|
||||
_lastIndex = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab);
|
||||
});
|
||||
Dispatcher.UIThread.Invoke(() => TabFrame.NavigateFromObject(viewModel, new FrameNavigationOptions {TransitionInfoOverride = GetTransitionInfo()}));
|
||||
}
|
||||
|
||||
private SlideNavigationTransitionInfo GetTransitionInfo()
|
||||
{
|
||||
if (ViewModel?.SelectedTab == null)
|
||||
return new SlideNavigationTransitionInfo();
|
||||
|
||||
SlideNavigationTransitionEffect effect = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab) > _lastIndex ? SlideNavigationTransitionEffect.FromRight : SlideNavigationTransitionEffect.FromLeft;
|
||||
SlideNavigationTransitionInfo info = new() {Effect = effect};
|
||||
_lastIndex = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab);
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
@ -35,5 +35,8 @@
|
||||
<GraphQL Update="Queries\GetCategories.graphql">
|
||||
<Generator>MSBuild:GenerateGraphQLCode</Generator>
|
||||
</GraphQL>
|
||||
<GraphQL Update="Queries\GetSubmittedEntries.graphql">
|
||||
<Generator>MSBuild:GenerateGraphQLCode</Generator>
|
||||
</GraphQL>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
query GetSubmittedEntries($filter: EntryFilterInput) {
|
||||
submittedEntries(where: $filter order: {createdAt: DESC}) {
|
||||
id
|
||||
name
|
||||
summary
|
||||
entryType
|
||||
downloads
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
@ -1,30 +1,19 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Services.MainWindow;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.UploadHandlers;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Services;
|
||||
|
||||
public class WorkshopService : IWorkshopService
|
||||
{
|
||||
private readonly Dictionary<Guid, Stream> _entryIconCache = new();
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IRouter _router;
|
||||
private readonly SemaphoreSlim _iconCacheLock = new(1);
|
||||
|
||||
public WorkshopService(IHttpClientFactory httpClientFactory, IMainWindowService mainWindowService, IRouter router)
|
||||
public WorkshopService(IHttpClientFactory httpClientFactory, IRouter router)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_router = router;
|
||||
mainWindowService.MainWindowClosed += (_, _) => Dispatcher.UIThread.InvokeAsync(async () =>
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
ClearCache();
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken)
|
||||
@ -48,52 +37,41 @@ public class WorkshopService : IWorkshopService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IWorkshopService.WorkshopStatus> GetWorkshopStatus()
|
||||
public async Task<IWorkshopService.WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Don't use the workshop client which adds auth headers
|
||||
HttpClient client = _httpClientFactory.CreateClient();
|
||||
HttpResponseMessage response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Head, WorkshopConstants.WORKSHOP_URL + "/status"));
|
||||
HttpResponseMessage response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Head, WorkshopConstants.WORKSHOP_URL + "/status"), cancellationToken);
|
||||
return new IWorkshopService.WorkshopStatus(response.IsSuccessStatusCode, response.StatusCode.ToString());
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new IWorkshopService.WorkshopStatus(false, e.Message);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
return new IWorkshopService.WorkshopStatus(false, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ValidateWorkshopStatus()
|
||||
public async Task<bool> ValidateWorkshopStatus(CancellationToken cancellationToken)
|
||||
{
|
||||
IWorkshopService.WorkshopStatus status = await GetWorkshopStatus();
|
||||
IWorkshopService.WorkshopStatus status = await GetWorkshopStatus(cancellationToken);
|
||||
if (!status.IsReachable)
|
||||
await _router.Navigate($"workshop/offline/{status.Message}");
|
||||
return status.IsReachable;
|
||||
}
|
||||
|
||||
private void ClearCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Stream> values = _entryIconCache.Values.ToList();
|
||||
_entryIconCache.Clear();
|
||||
foreach (Stream bitmap in values)
|
||||
bitmap.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IWorkshopService
|
||||
{
|
||||
Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken);
|
||||
Task<WorkshopStatus> GetWorkshopStatus();
|
||||
Task<bool> ValidateWorkshopStatus();
|
||||
Task<WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken);
|
||||
Task<bool> ValidateWorkshopStatus(CancellationToken cancellationToken);
|
||||
|
||||
public record WorkshopStatus(bool IsReachable, string Message);
|
||||
}
|
||||
@ -2,7 +2,7 @@ schema: schema.graphql
|
||||
extensions:
|
||||
endpoints:
|
||||
Default GraphQL Endpoint:
|
||||
url: https://workshop.artemis-rgb.com/graphql
|
||||
url: https://localhost:7281/graphql
|
||||
headers:
|
||||
user-agent: JS GraphQL
|
||||
introspect: true
|
||||
|
||||
@ -41,6 +41,7 @@ type Entry {
|
||||
id: UUID!
|
||||
images: [Image!]!
|
||||
latestRelease: Release
|
||||
latestReleaseId: UUID
|
||||
name: String!
|
||||
releases: [Release!]!
|
||||
summary: String!
|
||||
@ -62,6 +63,7 @@ type Query {
|
||||
entries(order: [EntrySortInput!], skip: Int, take: Int, where: EntryFilterInput): EntriesCollectionSegment
|
||||
entry(id: UUID!): Entry
|
||||
searchEntries(input: String!, order: [EntrySortInput!], type: EntryType, where: EntryFilterInput): [Entry!]!
|
||||
submittedEntries(order: [EntrySortInput!], where: EntryFilterInput): [Entry!]!
|
||||
}
|
||||
|
||||
type Release {
|
||||
@ -156,6 +158,8 @@ input EntryFilterInput {
|
||||
iconId: UuidOperationFilterInput
|
||||
id: UuidOperationFilterInput
|
||||
images: ListFilterInputTypeOfImageFilterInput
|
||||
latestRelease: ReleaseFilterInput
|
||||
latestReleaseId: UuidOperationFilterInput
|
||||
name: StringOperationFilterInput
|
||||
or: [EntryFilterInput!]
|
||||
releases: ListFilterInputTypeOfReleaseFilterInput
|
||||
@ -173,6 +177,8 @@ input EntrySortInput {
|
||||
icon: ImageSortInput
|
||||
iconId: SortEnumType
|
||||
id: SortEnumType
|
||||
latestRelease: ReleaseSortInput
|
||||
latestReleaseId: SortEnumType
|
||||
name: SortEnumType
|
||||
summary: SortEnumType
|
||||
}
|
||||
@ -267,6 +273,17 @@ input ReleaseFilterInput {
|
||||
version: StringOperationFilterInput
|
||||
}
|
||||
|
||||
input ReleaseSortInput {
|
||||
createdAt: SortEnumType
|
||||
downloadSize: SortEnumType
|
||||
downloads: SortEnumType
|
||||
entry: EntrySortInput
|
||||
entryId: SortEnumType
|
||||
id: SortEnumType
|
||||
md5Hash: SortEnumType
|
||||
version: SortEnumType
|
||||
}
|
||||
|
||||
input StringOperationFilterInput {
|
||||
and: [StringOperationFilterInput!]
|
||||
contains: String
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user