mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added workshop home, changed VM routing structure
This commit is contained in:
1 parent
99a365be0b
commit
65f81ab768
34 files changed
+667
-75
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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:search="clr-namespace:Artemis.UI.Screens.Workshop.Search"
|
||||
xmlns:workshop="clr-namespace:Artemis.WebClient.Workshop;assembly=Artemis.WebClient.Workshop"
|
||||
xmlns:windowing="clr-namespace:FluentAvalonia.UI.Windowing;assembly=FluentAvalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Search.SearchView"
|
||||
x:DataType="search:SearchViewModel">
|
||||
<UserControl.Styles>
|
||||
<StyleInclude Source="SearchViewStyles.axaml" />
|
||||
</UserControl.Styles>
|
||||
<Panel>
|
||||
<AutoCompleteBox Name="SearchBox"
|
||||
MaxWidth="500"
|
||||
Watermark="Search"
|
||||
Margin="0 5"
|
||||
ValueMemberBinding="{CompiledBinding Name, DataType=workshop:ISearchEntries_Entries_Nodes}"
|
||||
AsyncPopulator="{CompiledBinding SearchAsync}"
|
||||
SelectedItem="{CompiledBinding SelectedEntry}"
|
||||
FilterMode="None"
|
||||
windowing:AppWindow.AllowInteractionInTitleBar="True">
|
||||
<AutoCompleteBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="workshop:ISearchEntries_Entries_Nodes">
|
||||
<Panel>
|
||||
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center">
|
||||
<TextBlock Text="{CompiledBinding Name}" />
|
||||
<TextBlock Text="{CompiledBinding Summary}" Foreground="{DynamicResource TextFillColorSecondary}" />
|
||||
|
||||
<ItemsControl ItemsSource="{CompiledBinding Categories}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="5"></StackPanel>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Classes="category">
|
||||
<TextBlock Text="{CompiledBinding Name}"></TextBlock>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</DataTemplate>
|
||||
</AutoCompleteBox.ItemTemplate>
|
||||
</AutoCompleteBox>
|
||||
<ContentControl HorizontalAlignment="Right"
|
||||
Margin="0 0 50 0"
|
||||
Content="{CompiledBinding CurrentUserViewModel}"
|
||||
windowing:AppWindow.AllowInteractionInTitleBar="True"/>
|
||||
</Panel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Search;
|
||||
|
||||
public partial class SearchView : UserControl
|
||||
{
|
||||
public SearchView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Screens.Workshop.CurrentUser;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using ReactiveUI;
|
||||
using StrawberryShake;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Search;
|
||||
|
||||
public class SearchViewModel : ViewModelBase
|
||||
{
|
||||
public CurrentUserViewModel CurrentUserViewModel { get; }
|
||||
private readonly IRouter _router;
|
||||
private readonly IWorkshopClient _workshopClient;
|
||||
private EntryType? _entryType;
|
||||
private ISearchEntries_Entries_Nodes? _selectedEntry;
|
||||
|
||||
public SearchViewModel(IWorkshopClient workshopClient, IRouter router, CurrentUserViewModel currentUserViewModel)
|
||||
{
|
||||
CurrentUserViewModel = currentUserViewModel;
|
||||
_workshopClient = workshopClient;
|
||||
_router = router;
|
||||
SearchAsync = ExecuteSearchAsync;
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedEntry).WhereNotNull().Subscribe(NavigateToEntry);
|
||||
}
|
||||
|
||||
public Func<string?, CancellationToken, Task<IEnumerable<object>>> SearchAsync { get; }
|
||||
|
||||
public ISearchEntries_Entries_Nodes? SelectedEntry
|
||||
{
|
||||
get => _selectedEntry;
|
||||
set => RaiseAndSetIfChanged(ref _selectedEntry, value);
|
||||
}
|
||||
|
||||
public EntryType? EntryType
|
||||
{
|
||||
get => _entryType;
|
||||
set => RaiseAndSetIfChanged(ref _entryType, value);
|
||||
}
|
||||
|
||||
private void NavigateToEntry(ISearchEntries_Entries_Nodes entry)
|
||||
{
|
||||
string? url = null;
|
||||
if (entry.EntryType == WebClient.Workshop.EntryType.Profile)
|
||||
url = $"workshop/profiles/{entry.Id}";
|
||||
if (entry.EntryType == WebClient.Workshop.EntryType.Layout)
|
||||
url = $"workshop/layouts/{entry.Id}";
|
||||
|
||||
if (url != null)
|
||||
Task.Run(() => _router.Navigate(url));
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<object>> ExecuteSearchAsync(string? input, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return new List<object>();
|
||||
|
||||
EntryFilterInput filter;
|
||||
if (EntryType != null)
|
||||
filter = new EntryFilterInput
|
||||
{
|
||||
And = new[]
|
||||
{
|
||||
new EntryFilterInput {EntryType = new EntryTypeOperationFilterInput {Eq = EntryType}},
|
||||
new EntryFilterInput {Name = new StringOperationFilterInput {Contains = input}}
|
||||
}
|
||||
};
|
||||
else
|
||||
filter = new EntryFilterInput {Name = new StringOperationFilterInput {Contains = input}};
|
||||
|
||||
IOperationResult<ISearchEntriesResult> results = await _workshopClient.SearchEntries.ExecuteAsync(filter, cancellationToken);
|
||||
return results.Data?.Entries?.Nodes?.Cast<object>() ?? new List<object>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<Styles xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Design.PreviewWith>
|
||||
<Border Padding="10">
|
||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
||||
<Border Classes="category">
|
||||
<TextBlock Text="Media"></TextBlock>
|
||||
</Border>
|
||||
|
||||
<Border Classes="category">
|
||||
<TextBlock Text="Audio"></TextBlock>
|
||||
</Border>
|
||||
|
||||
<Border Classes="category">
|
||||
<TextBlock Text="Interaction"></TextBlock>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Design.PreviewWith>
|
||||
|
||||
<!-- Add Styles Here -->
|
||||
<Style Selector="Border.category">
|
||||
<Setter Property="Background" Value="{DynamicResource ControlSolidFillColorDefaultBrush}" />
|
||||
<Setter Property="CornerRadius" Value="12" />
|
||||
<Setter Property="Padding" Value="6 1"></Setter>
|
||||
<Setter Property="TextBlock.FontSize" Value="12" />
|
||||
</Style>
|
||||
</Styles>
|
||||
Reference in new issue
Block a user