1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Workshop Library - Added library pages

UI - Tweaked design to more closely match WinUI 3 gallery examples
This commit is contained in:
Robert 2023-09-01 20:33:32 +02:00
parent e545d2f3da
commit 9c6d7329a6
25 changed files with 519 additions and 288 deletions

View File

@ -23,15 +23,11 @@
</Border> </Border>
</StackPanel> </StackPanel>
</Design.PreviewWith> </Design.PreviewWith>
<Styles.Resources>
<CornerRadius x:Key="CardCornerRadius">8</CornerRadius>
</Styles.Resources>
<!-- Add Styles Here --> <!-- Add Styles Here -->
<Style Selector="Border.router-container"> <Style Selector="Border.router-container">
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" /> <Setter Property="Background" Value="{DynamicResource NavigationViewContentBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource CardStrokeColorDefaultBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource NavigationViewContentGridBorderBrush}" />
<Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="8 0 0 0" /> <Setter Property="CornerRadius" Value="8 0 0 0" />
<Setter Property="ClipToBounds" Value="True" /> <Setter Property="ClipToBounds" Value="True" />
@ -39,18 +35,18 @@
<Style Selector="Border.card"> <Style Selector="Border.card">
<Setter Property="Padding" Value="16" /> <Setter Property="Padding" Value="16" />
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" /> <Setter Property="Background" Value="{DynamicResource NavigationViewContentBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource CardStrokeColorDefaultBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource NavigationViewContentGridBorderBrush}" />
<Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{DynamicResource CardCornerRadius}" /> <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
</Style> </Style>
<Style Selector="Border.card-condensed"> <Style Selector="Border.card-condensed">
<Setter Property="Padding" Value="8" /> <Setter Property="Padding" Value="8" />
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" /> <Setter Property="Background" Value="{DynamicResource NavigationViewContentBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource CardStrokeColorDefaultBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource NavigationViewContentGridBorderBrush}" />
<Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{DynamicResource CardCornerRadius}" /> <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
</Style> </Style>
<Style Selector="Border.card-separator"> <Style Selector="Border.card-separator">

File diff suppressed because one or more lines are too long

View 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)));
}
}

View File

@ -21,7 +21,7 @@ public static class Routes
{ {
new RouteRegistration<BlankViewModel>("blank"), new RouteRegistration<BlankViewModel>("blank"),
new RouteRegistration<HomeViewModel>("home"), new RouteRegistration<HomeViewModel>("home"),
#if DEBUG #if DEBUG
new RouteRegistration<WorkshopViewModel>("workshop") new RouteRegistration<WorkshopViewModel>("workshop")
{ {
Children = new List<IRouterRegistration>() Children = new List<IRouterRegistration>()
@ -31,14 +31,17 @@ public static class Routes
new RouteRegistration<ProfileDetailsViewModel>("profiles/{entryId:guid}"), new RouteRegistration<ProfileDetailsViewModel>("profiles/{entryId:guid}"),
new RouteRegistration<LayoutListViewModel>("layouts/{page:int}"), new RouteRegistration<LayoutListViewModel>("layouts/{page:int}"),
new RouteRegistration<LayoutDetailsViewModel>("layouts/{entryId:guid}"), new RouteRegistration<LayoutDetailsViewModel>("layouts/{entryId:guid}"),
new RouteRegistration<WorkshopLibraryViewModel>("library") {Children = new List<IRouterRegistration>() new RouteRegistration<WorkshopLibraryViewModel>("library")
{ {
new RouteRegistration<LibraryInstalledViewModel>("installed"), Children = new List<IRouterRegistration>()
new RouteRegistration<LibrarySubmissionsViewModel>("submissions"), {
}} new RouteRegistration<LibraryInstalledViewModel>("installed"),
new RouteRegistration<LibrarySubmissionsViewModel>("submissions"),
}
}
} }
}, },
#endif #endif
new RouteRegistration<SurfaceEditorViewModel>("surface-editor"), new RouteRegistration<SurfaceEditorViewModel>("surface-editor"),
new RouteRegistration<SettingsViewModel>("settings") new RouteRegistration<SettingsViewModel>("settings")
{ {

View File

@ -43,6 +43,7 @@ public class SidebarViewModel : ActivatableViewModelBase
{ {
new(MaterialIconKind.FolderVideo, "Profiles", "workshop/profiles/1", "workshop/profiles"), new(MaterialIconKind.FolderVideo, "Profiles", "workshop/profiles/1", "workshop/profiles"),
new(MaterialIconKind.KeyboardVariant, "Layouts", "workshop/layouts/1", "workshop/layouts"), new(MaterialIconKind.KeyboardVariant, "Layouts", "workshop/layouts/1", "workshop/layouts"),
new(MaterialIconKind.Bookshelf, "Library", "workshop/library"),
}), }),
#endif #endif
new(MaterialIconKind.Devices, "Surface Editor", "surface-editor"), new(MaterialIconKind.Devices, "Surface Editor", "surface-editor"),

View File

@ -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;
}

View File

@ -7,16 +7,15 @@
xmlns:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia" xmlns:il="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
xmlns:converters="clr-namespace:Artemis.UI.Converters" xmlns:converters="clr-namespace:Artemis.UI.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="110" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="110"
x:Class="Artemis.UI.Screens.Workshop.Entries.EntryListView" x:Class="Artemis.UI.Screens.Workshop.Entries.EntryListItemView"
x:DataType="entries1:EntryListViewModel"> x:DataType="entries1:EntryListItemViewModel">
<UserControl.Resources> <UserControl.Resources>
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" /> <converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
<converters:DateTimeConverter x:Key="DateTimeConverter" /> <converters:DateTimeConverter x:Key="DateTimeConverter" />
</UserControl.Resources> </UserControl.Resources>
<Button MinHeight="110" <Button MinHeight="110"
MaxHeight="140" MaxHeight="140"
Padding="16" Padding="12"
CornerRadius="8"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
Command="{CompiledBinding NavigateToEntry}" Command="{CompiledBinding NavigateToEntry}"
@ -24,8 +23,7 @@
<Grid ColumnDefinitions="Auto,*,Auto"> <Grid ColumnDefinitions="Auto,*,Auto">
<!-- Icon --> <!-- Icon -->
<Border Grid.Column="0" <Border Grid.Column="0"
CornerRadius="12" CornerRadius="6"
Background="{StaticResource ControlStrokeColorOnAccentDefault}"
VerticalAlignment="Center" VerticalAlignment="Center"
Margin="0 0 10 0" Margin="0 0 10 0"
Width="80" Width="80"

View File

@ -2,9 +2,9 @@ using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.Entries; namespace Artemis.UI.Screens.Workshop.Entries;
public partial class EntryListView : ReactiveUserControl<EntryListViewModel> public partial class EntryListItemView : ReactiveUserControl<EntryListItemViewModel>
{ {
public EntryListView() public EntryListItemView()
{ {
InitializeComponent(); InitializeComponent();
} }

View File

@ -13,11 +13,11 @@ using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.Entries; namespace Artemis.UI.Screens.Workshop.Entries;
public class EntryListViewModel : ActivatableViewModelBase public class EntryListItemViewModel : ActivatableViewModelBase
{ {
private readonly IRouter _router; private readonly IRouter _router;
public EntryListViewModel(IGetEntries_Entries_Items entry, IRouter router) public EntryListItemViewModel(IGetEntries_Entries_Items entry, IRouter router)
{ {
_router = router; _router = router;

View File

@ -2,6 +2,7 @@ using System.Reactive;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.UI.Extensions;
using Artemis.UI.Screens.Workshop.SubmissionWizard; using Artemis.UI.Screens.Workshop.SubmissionWizard;
using Artemis.UI.Shared; using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing; using Artemis.UI.Shared.Routing;
@ -27,7 +28,7 @@ public class WorkshopHomeViewModel : ActivatableViewModelBase, IWorkshopViewMode
AddSubmission = ReactiveCommand.CreateFromTask(ExecuteAddSubmission, this.WhenAnyValue(vm => vm.WorkshopReachable)); AddSubmission = ReactiveCommand.CreateFromTask(ExecuteAddSubmission, this.WhenAnyValue(vm => vm.WorkshopReachable));
Navigate = ReactiveCommand.CreateFromTask<string>(async r => await router.Navigate(r), 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; } public ReactiveCommand<Unit, Unit> AddSubmission { get; }
@ -44,10 +45,5 @@ public class WorkshopHomeViewModel : ActivatableViewModelBase, IWorkshopViewMode
await _windowService.ShowDialogAsync<SubmissionWizardViewModel, bool>(); await _windowService.ShowDialogAsync<SubmissionWizardViewModel, bool>();
} }
private async Task ValidateWorkshopStatus()
{
WorkshopReachable = await _workshopService.ValidateWorkshopStatus();
}
public EntryType? EntryType => null; public EntryType? EntryType => null;
} }

View File

@ -1,4 +1,4 @@
using System.Net;
using System.Reactive; using System.Reactive;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -41,7 +41,7 @@ public class WorkshopOfflineViewModel : RoutableScreen<ActivatableViewModelBase,
private async Task ExecuteRetry(CancellationToken cancellationToken) private async Task ExecuteRetry(CancellationToken cancellationToken)
{ {
IWorkshopService.WorkshopStatus status = await _workshopService.GetWorkshopStatus(); IWorkshopService.WorkshopStatus status = await _workshopService.GetWorkshopStatus(cancellationToken);
if (status.IsReachable) if (status.IsReachable)
await _router.Navigate("workshop"); await _router.Navigate("workshop");

View File

@ -3,23 +3,40 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:layout="clr-namespace:Artemis.UI.Screens.Workshop.Layout" 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" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.Layout.LayoutListView" x:Class="Artemis.UI.Screens.Workshop.Layout.LayoutListView"
x:DataType="layout:LayoutListViewModel"> x:DataType="layout:LayoutListViewModel">
<Border Classes="router-container"> <Border Classes="router-container">
<Grid ColumnDefinitions="300,*" Margin="10"> <Grid ColumnDefinitions="300,*" Margin="10" RowDefinitions="*,Auto">
<Border Classes="card-condensed" Grid.Column="0" Margin="0 0 10 0"> <StackPanel Grid.Column="0" Grid.RowSpan="2" Margin="0 0 10 0" VerticalAlignment="Top">
<StackPanel> <Border Classes="card" VerticalAlignment="Stretch">
<TextBlock Classes="h3">Categories</TextBlock> <StackPanel>
<ContentControl Content="{CompiledBinding CategoriesViewModel}"></ContentControl> <TextBlock Theme="{StaticResource SubtitleTextBlockStyle}">Categories</TextBlock>
</StackPanel> <Border Classes="card-separator" />
</Border> <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"> <pagination:Pagination Grid.Column="1"
<TextBlock> Grid.Row="1"
<Run Text="Layout list main panel, page: " /><Run Text="{CompiledBinding Page}"></Run> Margin="0 20 0 10"
</TextBlock> IsVisible="{CompiledBinding ShowPagination}"
</Border> Value="{CompiledBinding Page}"
Maximum="{CompiledBinding TotalPages}"
HorizontalAlignment="Center" />
</Grid> </Grid>
</Border> </Border>
</UserControl> </UserControl>

View File

@ -1,36 +1,44 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks;
using Artemis.UI.Screens.Workshop.Categories; using Artemis.UI.Screens.Workshop.Categories;
using Artemis.UI.Screens.Workshop.Parameters; using Artemis.UI.Screens.Workshop.Entries;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing; using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop; using Artemis.WebClient.Workshop;
namespace Artemis.UI.Screens.Workshop.Layout; namespace Artemis.UI.Screens.Workshop.Layout;
public class LayoutListViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopListParameters>, IWorkshopViewModel public class LayoutListViewModel : EntryListBaseViewModel
{ {
private int _page; /// <inheritdoc />
public LayoutListViewModel(IWorkshopClient workshopClient,
public LayoutListViewModel(CategoriesViewModel categoriesViewModel) 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; return $"workshop/layouts/{page}";
set => RaiseAndSetIfChanged(ref _page, value); }
/// <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) #endregion
{
Page = Math.Max(1, parameters.Page);
return Task.CompletedTask;
}
public EntryType? EntryType => WebClient.Workshop.EntryType.Layout;
} }

View File

@ -2,7 +2,67 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" xmlns:tabs="clr-namespace:Artemis.UI.Screens.Workshop.Library.Tabs"
x:Class="Artemis.UI.Screens.Workshop.Library.Tabs.LibrarySubmissionsView"> xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
Submission management here 😗 xmlns:workshop="clr-namespace:Artemis.WebClient.Workshop;assembly=Artemis.WebClient.Workshop"
</UserControl> 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>

View File

@ -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;
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; 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;
} }

View File

@ -2,26 +2,25 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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:library="clr-namespace:Artemis.UI.Screens.Workshop.Library"
xmlns:routing="clr-namespace:Artemis.UI.Routing" xmlns:ui="clr-namespace:Artemis.UI"
xmlns:ui1="clr-namespace:Artemis.UI"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.Library.WorkshopLibraryView" x:Class="Artemis.UI.Screens.Workshop.Library.WorkshopLibraryView"
x:DataType="library:WorkshopLibraryViewModel"> x:DataType="library:WorkshopLibraryViewModel">
<ui:NavigationView PaneDisplayMode="Top" MenuItemsSource="{CompiledBinding Tabs}" SelectedItem="{CompiledBinding SelectedTab}"> <controls:NavigationView PaneDisplayMode="Top" MenuItemsSource="{CompiledBinding Tabs}" SelectedItem="{CompiledBinding SelectedTab}">
<ui:NavigationView.Styles> <controls:NavigationView.Styles>
<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" /> <Setter Property="CornerRadius" Value="8 0 0 0" />
</Style> </Style>
</Styles> </Styles>
</ui:NavigationView.Styles> </controls:NavigationView.Styles>
<ui:Frame Name="TabFrame" IsNavigationStackEnabled="False" CacheSize="0"> <controls:Frame Name="TabFrame" IsNavigationStackEnabled="False" CacheSize="0" Padding="20">
<ui:Frame.NavigationPageFactory> <controls:Frame.NavigationPageFactory>
<ui1:PageFactory/> <ui:PageFactory/>
</ui:Frame.NavigationPageFactory> </controls:Frame.NavigationPageFactory>
</ui:Frame> </controls:Frame>
</ui:NavigationView> </controls:NavigationView>
</UserControl> </UserControl>

View File

@ -21,17 +21,18 @@ public partial class WorkshopLibraryView : ReactiveUserControl<WorkshopLibraryVi
private void Navigate(ViewModelBase viewModel) private void Navigate(ViewModelBase viewModel)
{ {
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() => TabFrame.NavigateFromObject(viewModel, new FrameNavigationOptions {TransitionInfoOverride = GetTransitionInfo()}));
{ }
if (ViewModel == null)
return; private SlideNavigationTransitionInfo GetTransitionInfo()
{
SlideNavigationTransitionInfo transitionInfo = new() if (ViewModel?.SelectedTab == null)
{ return new SlideNavigationTransitionInfo();
Effect = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab) > _lastIndex ? SlideNavigationTransitionEffect.FromRight : SlideNavigationTransitionEffect.FromLeft
}; SlideNavigationTransitionEffect effect = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab) > _lastIndex ? SlideNavigationTransitionEffect.FromRight : SlideNavigationTransitionEffect.FromLeft;
TabFrame.NavigateFromObject(viewModel, new FrameNavigationOptions {TransitionInfoOverride = transitionInfo}); SlideNavigationTransitionInfo info = new() {Effect = effect};
_lastIndex = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab); _lastIndex = ViewModel.Tabs.IndexOf(ViewModel.SelectedTab);
});
return info;
} }
} }

View File

@ -23,8 +23,7 @@
<StackPanel Grid.Row="1" Grid.Column="0" Margin="0 0 10 0" Spacing="10"> <StackPanel Grid.Row="1" Grid.Column="0" Margin="0 0 10 0" Spacing="10">
<Border Classes="card" VerticalAlignment="Top"> <Border Classes="card" VerticalAlignment="Top">
<StackPanel> <StackPanel>
<Border CornerRadius="12" <Border CornerRadius="6"
Background="{StaticResource ControlStrokeColorOnAccentDefault}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Margin="0 0 10 0" Margin="0 0 10 0"
Width="80" Width="80"

View File

@ -10,16 +10,18 @@
<Border Classes="router-container"> <Border Classes="router-container">
<Grid ColumnDefinitions="300,*" Margin="10" RowDefinitions="*,Auto"> <Grid ColumnDefinitions="300,*" Margin="10" RowDefinitions="*,Auto">
<StackPanel Grid.Column="0" Grid.RowSpan="2" Margin="0 0 10 0" VerticalAlignment="Top"> <StackPanel Grid.Column="0" Grid.RowSpan="2" Margin="0 0 10 0" VerticalAlignment="Top">
<TextBlock Classes="card-title" Margin="0 0 0 5"> <Border Classes="card" VerticalAlignment="Stretch">
Categories <StackPanel>
</TextBlock> <TextBlock Theme="{StaticResource SubtitleTextBlockStyle}">Categories</TextBlock>
<Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0"> <Border Classes="card-separator" />
<ContentControl Content="{CompiledBinding CategoriesViewModel}"></ContentControl> <ContentControl Content="{CompiledBinding CategoriesViewModel}"></ContentControl>
</StackPanel>
</Border> </Border>
</StackPanel> </StackPanel>
<ProgressBar Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" Margin="0 26 20 0" IsVisible="{CompiledBinding IsLoading}" IsIndeterminate="True"/> <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" Margin="0 26 0 0">
<ScrollViewer Grid.Column="1" Grid.Row="0">
<ItemsRepeater ItemsSource="{CompiledBinding Entries}" Margin="0 0 20 0"> <ItemsRepeater ItemsSource="{CompiledBinding Entries}" Margin="0 0 20 0">
<ItemsRepeater.ItemTemplate> <ItemsRepeater.ItemTemplate>
<DataTemplate> <DataTemplate>

View File

@ -1,165 +1,44 @@
using System; 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.Categories;
using Artemis.UI.Screens.Workshop.Entries; 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.Routing;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Builders;
using Artemis.WebClient.Workshop; using Artemis.WebClient.Workshop;
using Avalonia.Threading;
using DryIoc.ImTools;
using DynamicData;
using ReactiveUI;
using StrawberryShake;
namespace Artemis.UI.Screens.Workshop.Profile; namespace Artemis.UI.Screens.Workshop.Profile;
public class ProfileListViewModel : RoutableScreen<ActivatableViewModelBase, WorkshopListParameters>, IWorkshopViewModel public class ProfileListViewModel : EntryListBaseViewModel
{ {
private readonly INotificationService _notificationService; /// <inheritdoc />
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;
public ProfileListViewModel(IWorkshopClient workshopClient, public ProfileListViewModel(IWorkshopClient workshopClient,
IRouter router, IRouter router,
CategoriesViewModel categoriesViewModel, CategoriesViewModel categoriesViewModel,
INotificationService notificationService, 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; #region Overrides of EntryListBaseViewModel
_entries.Connect() /// <inheritdoc />
.ObserveOn(new AvaloniaSynchronizationContext(DispatcherPriority.SystemIdle)) protected override string GetPagePath(int page)
.Transform(getEntryListViewModel) {
.Bind(out ReadOnlyObservableCollection<EntryListViewModel> entries) return $"workshop/profiles/{page}";
.Subscribe(); }
Entries = entries;
/// <inheritdoc />
// Respond to page changes protected override EntryFilterInput GetFilter()
this.WhenAnyValue(vm => vm.Page).Skip(1).Subscribe(p => Task.Run(() => router.Navigate($"workshop/profiles/{p}"))); {
return new EntryFilterInput
// Respond to filter changes
this.WhenActivated(d => CategoriesViewModel.WhenAnyValue(vm => vm.CategoryFilters).Skip(1).Subscribe(_ =>
{ {
// Reset to page one, will trigger a query And = new[]
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)
{ {
TotalPages = (int) Math.Ceiling(entries.Data.Entries.TotalCount / (double) EntriesPerPage); new EntryFilterInput {EntryType = new EntryTypeOperationFilterInput {Eq = WebClient.Workshop.EntryType.Profile}},
_entries.Edit(e => base.GetFilter()
{
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;
}
}
private EntryFilterInput GetFilter()
{
EntryFilterInput filter = new()
{
EntryType = new EntryTypeOperationFilterInput {Eq = WebClient.Workshop.EntryType.Profile},
And = CategoriesViewModel.CategoryFilters
}; };
return filter;
} }
public EntryType? EntryType => null; #endregion
} }

View File

@ -35,5 +35,8 @@
<GraphQL Update="Queries\GetCategories.graphql"> <GraphQL Update="Queries\GetCategories.graphql">
<Generator>MSBuild:GenerateGraphQLCode</Generator> <Generator>MSBuild:GenerateGraphQLCode</Generator>
</GraphQL> </GraphQL>
<GraphQL Update="Queries\GetSubmittedEntries.graphql">
<Generator>MSBuild:GenerateGraphQLCode</Generator>
</GraphQL>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,10 @@
query GetSubmittedEntries($filter: EntryFilterInput) {
submittedEntries(where: $filter order: {createdAt: DESC}) {
id
name
summary
entryType
downloads
createdAt
}
}

View File

@ -1,30 +1,19 @@
using System.Net;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using Artemis.UI.Shared.Routing; using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services.MainWindow;
using Artemis.UI.Shared.Utilities; using Artemis.UI.Shared.Utilities;
using Artemis.WebClient.Workshop.UploadHandlers; using Artemis.WebClient.Workshop.UploadHandlers;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
namespace Artemis.WebClient.Workshop.Services; namespace Artemis.WebClient.Workshop.Services;
public class WorkshopService : IWorkshopService public class WorkshopService : IWorkshopService
{ {
private readonly Dictionary<Guid, Stream> _entryIconCache = new();
private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;
private readonly IRouter _router; 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; _httpClientFactory = httpClientFactory;
_router = router; _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) public async Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken)
@ -48,52 +37,41 @@ public class WorkshopService : IWorkshopService
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task<IWorkshopService.WorkshopStatus> GetWorkshopStatus() public async Task<IWorkshopService.WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken)
{ {
try try
{ {
// Don't use the workshop client which adds auth headers // Don't use the workshop client which adds auth headers
HttpClient client = _httpClientFactory.CreateClient(); 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()); return new IWorkshopService.WorkshopStatus(response.IsSuccessStatusCode, response.StatusCode.ToString());
} }
catch (OperationCanceledException e)
{
return new IWorkshopService.WorkshopStatus(false, e.Message);
}
catch (HttpRequestException e) catch (HttpRequestException e)
{ {
return new IWorkshopService.WorkshopStatus(false, e.Message); return new IWorkshopService.WorkshopStatus(false, e.Message);
} }
} }
/// <param name="cancellationToken"></param>
/// <inheritdoc /> /// <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) if (!status.IsReachable)
await _router.Navigate($"workshop/offline/{status.Message}"); await _router.Navigate($"workshop/offline/{status.Message}");
return status.IsReachable; 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 public interface IWorkshopService
{ {
Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken); Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken);
Task<WorkshopStatus> GetWorkshopStatus(); Task<WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken);
Task<bool> ValidateWorkshopStatus(); Task<bool> ValidateWorkshopStatus(CancellationToken cancellationToken);
public record WorkshopStatus(bool IsReachable, string Message); public record WorkshopStatus(bool IsReachable, string Message);
} }

View File

@ -2,7 +2,7 @@ schema: schema.graphql
extensions: extensions:
endpoints: endpoints:
Default GraphQL Endpoint: Default GraphQL Endpoint:
url: https://workshop.artemis-rgb.com/graphql url: https://localhost:7281/graphql
headers: headers:
user-agent: JS GraphQL user-agent: JS GraphQL
introspect: true introspect: true

View File

@ -41,6 +41,7 @@ type Entry {
id: UUID! id: UUID!
images: [Image!]! images: [Image!]!
latestRelease: Release latestRelease: Release
latestReleaseId: UUID
name: String! name: String!
releases: [Release!]! releases: [Release!]!
summary: String! summary: String!
@ -62,6 +63,7 @@ type Query {
entries(order: [EntrySortInput!], skip: Int, take: Int, where: EntryFilterInput): EntriesCollectionSegment entries(order: [EntrySortInput!], skip: Int, take: Int, where: EntryFilterInput): EntriesCollectionSegment
entry(id: UUID!): Entry entry(id: UUID!): Entry
searchEntries(input: String!, order: [EntrySortInput!], type: EntryType, where: EntryFilterInput): [Entry!]! searchEntries(input: String!, order: [EntrySortInput!], type: EntryType, where: EntryFilterInput): [Entry!]!
submittedEntries(order: [EntrySortInput!], where: EntryFilterInput): [Entry!]!
} }
type Release { type Release {
@ -156,6 +158,8 @@ input EntryFilterInput {
iconId: UuidOperationFilterInput iconId: UuidOperationFilterInput
id: UuidOperationFilterInput id: UuidOperationFilterInput
images: ListFilterInputTypeOfImageFilterInput images: ListFilterInputTypeOfImageFilterInput
latestRelease: ReleaseFilterInput
latestReleaseId: UuidOperationFilterInput
name: StringOperationFilterInput name: StringOperationFilterInput
or: [EntryFilterInput!] or: [EntryFilterInput!]
releases: ListFilterInputTypeOfReleaseFilterInput releases: ListFilterInputTypeOfReleaseFilterInput
@ -173,6 +177,8 @@ input EntrySortInput {
icon: ImageSortInput icon: ImageSortInput
iconId: SortEnumType iconId: SortEnumType
id: SortEnumType id: SortEnumType
latestRelease: ReleaseSortInput
latestReleaseId: SortEnumType
name: SortEnumType name: SortEnumType
summary: SortEnumType summary: SortEnumType
} }
@ -267,6 +273,17 @@ input ReleaseFilterInput {
version: StringOperationFilterInput version: StringOperationFilterInput
} }
input ReleaseSortInput {
createdAt: SortEnumType
downloadSize: SortEnumType
downloads: SortEnumType
entry: EntrySortInput
entryId: SortEnumType
id: SortEnumType
md5Hash: SortEnumType
version: SortEnumType
}
input StringOperationFilterInput { input StringOperationFilterInput {
and: [StringOperationFilterInput!] and: [StringOperationFilterInput!]
contains: String contains: String