Fix more edge cases

This commit is contained in:
TheXamlGuy
2024-05-31 22:50:52 +01:00
parent 718e4d0c0d
commit 07b8661f4a
18 changed files with 46 additions and 65 deletions
+5 -5
View File
@@ -110,12 +110,12 @@ public partial class App : Application
services.AddTemplate<ItemCategoryCollectionViewModel, ItemCategoryCollectionView>("ItemCategoryCollection"); services.AddTemplate<ItemCategoryCollectionViewModel, ItemCategoryCollectionView>("ItemCategoryCollection");
services.AddTemplate<ItemCategoryNavigationViewModel, ItemCategoryNavigationView>(); services.AddTemplate<ItemCategoryNavigationViewModel, ItemCategoryNavigationView>();
services.AddHandler<AggerateItemCategoryViewModelHandler>(); services.AddHandler<AggregateItemCategoryViewModelHandler>();
services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>(); services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>();
services.AddTemplate<ItemViewModel, ItemView>("Item"); services.AddTemplate<ItemViewModel, ItemView>("Item");
services.AddHandler<AggerateItemContentViewModelHandler>(); services.AddHandler<AggregateItemContentViewModelHandler>();
services.AddTemplate<ItemCommandHeaderViewModel, ItemCommandHeaderView>("ItemCommandHeader"); services.AddTemplate<ItemCommandHeaderViewModel, ItemCommandHeaderView>("ItemCommandHeader");
@@ -134,8 +134,8 @@ public partial class App : Application
services.AddScoped<IValueStore<Item<(Guid, string)>>, ValueStore<Item<(Guid, string)>>>(); services.AddScoped<IValueStore<Item<(Guid, string)>>, ValueStore<Item<(Guid, string)>>>();
services.AddHandler<ConfirmUpdateItemHandler>(nameof(Update)); services.AddHandler<ConfirmUpdateItemHandler>(nameof(ItemState.Write));
services.AddHandler<ConfirmCreateItemHandler>(nameof(Create)); services.AddHandler<ConfirmCreateItemHandler>(nameof(ItemState.New));
services.AddHandler<ArchiveItemHandler>(); services.AddHandler<ArchiveItemHandler>();
services.AddHandler<UnarchiveItemHandler>(); services.AddHandler<UnarchiveItemHandler>();
@@ -154,7 +154,7 @@ public partial class App : Application
services.AddInitializer<LockerInitializer>(); services.AddInitializer<LockerInitializer>();
services.AddTemplate<MainViewModel, MainView>("Main"); services.AddTemplate<MainViewModel, MainView>("Main");
services.AddHandler<AggerateMainViewModelHandler>(); services.AddHandler<AggregateMainViewModelHandler>();
services.AddTransient<FooterViewModel>(); services.AddTransient<FooterViewModel>();
@@ -26,6 +26,7 @@
</DataTriggerBehavior> </DataTriggerBehavior>
</Interaction.Behaviors> </Interaction.Behaviors>
<ListBox <ListBox
x:Name="foo"
Margin="2,-1,0,0" Margin="2,-1,0,0"
AutoScrollToSelectedItem="True" AutoScrollToSelectedItem="True"
ItemTemplate="{ReflectionBinding Template}" ItemTemplate="{ReflectionBinding Template}"
@@ -5,6 +5,14 @@ namespace Bitvault.Avalonia;
public partial class ItemCollectionView : public partial class ItemCollectionView :
UserControl UserControl
{ {
public ItemCollectionView() => public ItemCollectionView()
{
InitializeComponent(); InitializeComponent();
foo.SelectionChanged += Foo_SelectionChanged;
}
private void Foo_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
}
} }
+1 -1
View File
@@ -8,7 +8,7 @@
<PersonPicture <PersonPicture
Width="144" Width="144"
Height="144" Height="144"
DisplayName="{Binding Value}" /> DisplayName="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />
<TextBox <TextBox
MaxWidth="360" MaxWidth="360"
Text="{Binding Value}" Text="{Binding Value}"
+5 -22
View File
@@ -3,40 +3,23 @@
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Bitvault" xmlns:vm="using:Bitvault"
x:DataType="vm:ItemNavigationViewModel"> x:DataType="vm:ItemNavigationViewModel"
ListBoxExtension.IsItemInvokedEnabled="True">
<ListBoxItem.Resources> <ListBoxItem.Resources>
<SolidColorBrush x:Key="StarredIconForegroundBrush" Color="#FFEDB120" /> <SolidColorBrush x:Key="StarredIconForegroundBrush" Color="#FFEDB120" />
</ListBoxItem.Resources> </ListBoxItem.Resources>
<Interaction.Behaviors> <Interaction.Behaviors>
<AttachedBehaviour> <AttachedEventTriggerBehaviour RoutedEvent="{x:Static ListBoxExtension.ItemInvokedEvent}">
<ConditionAction>
<ConditionAction.Condition>
<ConditionalExpression ForwardChaining="And">
<ComparisonCondition LeftOperand="{Binding Selected}" RightOperand="True" />
</ConditionalExpression>
</ConditionAction.Condition>
<NavigateAction
Region="{Binding Named, StringFormat='{}{0}:Content'}"
Route="Item"
Scope="self">
<Parameter Key="State" Value="{x:Static vm:ItemState.Read}" />
<Parameter Key="Name" Value="{Binding Name}" />
<Parameter Key="Favourite" Value="{Binding Favourite}" />
<Parameter Key="Archived" Value="{Binding Archived}" />
</NavigateAction>
</ConditionAction>
</AttachedBehaviour>
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
<NavigateAction <NavigateAction
Region="{Binding Named, StringFormat='{}{0}:Content'}" Region="{Binding Named, StringFormat='{}{0}:Content'}"
Route="Item" Route="Item"
Scope="self"> Scope="self">
<Parameter Key="Name" Value="{Binding Name}" />
<Parameter Key="State" Value="{x:Static vm:ItemState.Read}" /> <Parameter Key="State" Value="{x:Static vm:ItemState.Read}" />
<Parameter Key="Name" Value="{Binding Name}" />
<Parameter Key="Favourite" Value="{Binding Favourite}" /> <Parameter Key="Favourite" Value="{Binding Favourite}" />
<Parameter Key="Archived" Value="{Binding Archived}" /> <Parameter Key="Archived" Value="{Binding Archived}" />
</NavigateAction> </NavigateAction>
</DataTriggerBehavior> </AttachedEventTriggerBehaviour>
</Interaction.Behaviors> </Interaction.Behaviors>
<Grid Background="Transparent" ColumnDefinitions="Auto,*"> <Grid Background="Transparent" ColumnDefinitions="Auto,*">
<PersonPicture <PersonPicture
+2 -2
View File
@@ -9,7 +9,7 @@
Content="{Binding Name}" Content="{Binding Name}"
IsExpanded="{Binding Expanded}" IsExpanded="{Binding Expanded}"
MenuItemsSource="{Binding}" MenuItemsSource="{Binding}"
NavigationViewItemExtension.IsItemClickEnabled="True" NavigationViewExtension.IsItemInvokedEnabled="True"
SelectsOnInvoked="True"> SelectsOnInvoked="True">
<Interaction.Behaviors> <Interaction.Behaviors>
<DataTriggerBehavior Binding="{Binding Opened}" Value="False"> <DataTriggerBehavior Binding="{Binding Opened}" Value="False">
@@ -64,7 +64,7 @@
<InvokeNavigationViewItemAction /> <InvokeNavigationViewItemAction />
</ConditionAction> </ConditionAction>
</AttachedBehaviour> </AttachedBehaviour>
<AttachedEventTriggerBehaviour RoutedEvent="{x:Static NavigationViewItemExtension.ItemClickEvent}"> <AttachedEventTriggerBehaviour RoutedEvent="{x:Static NavigationViewExtension.ItemInvokedEvent}">
<ConditionAction> <ConditionAction>
<ConditionAction.Condition> <ConditionAction.Condition>
<ConditionalExpression ForwardChaining="And"> <ConditionalExpression ForwardChaining="And">
@@ -2,7 +2,7 @@
namespace Bitvault; namespace Bitvault;
public class AggerateItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors, public class AggregateItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors,
IServiceFactory serviceFactory, IServiceFactory serviceFactory,
IPublisher publisher) : IPublisher publisher) :
INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>> INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>>
@@ -2,7 +2,7 @@
namespace Bitvault; namespace Bitvault;
public class AggerateItemContentViewModelHandler(IValueStore<Item<(Guid, string)>> valueStore, public class AggregateItemContentViewModelHandler(IValueStore<Item<(Guid, string)>> valueStore,
IMediator mediator, IMediator mediator,
IServiceFactory serviceFactory, IServiceFactory serviceFactory,
IPublisher publisher) : IPublisher publisher) :
@@ -6,13 +6,15 @@ namespace Bitvault;
public class AggerateItemViewModelHandler(IMediator mediator, public class AggerateItemViewModelHandler(IMediator mediator,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
ICache<Item<(Guid, string)>> cache, ICache<Item<(Guid, string)>> cache,
IPublisher publisher) : IPublisher publisher,
INotificationHandler<AggerateEventArgs<ItemNavigationViewModel, LockerViewModelConfiguration dd) :
INotificationHandler<AggregateEventArgs<ItemNavigationViewModel,
LockerViewModelConfiguration>> LockerViewModelConfiguration>>
{ {
public async Task Handle(AggerateEventArgs<ItemNavigationViewModel, public async Task Handle(AggregateEventArgs<ItemNavigationViewModel,
LockerViewModelConfiguration> args) LockerViewModelConfiguration> args)
{ {
var ddddd = dd;
if (args.Options is LockerViewModelConfiguration configuration) if (args.Options is LockerViewModelConfiguration configuration)
{ {
cache.Clear(); cache.Clear();
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
public class AggerateMainViewModelHandler(IPublisher publisher, public class AggregateMainViewModelHandler(IPublisher publisher,
ILockerHostCollection lockers) : ILockerHostCollection lockers) :
INotificationHandler<AggerateEventArgs<IMainNavigationViewModel>> INotificationHandler<AggerateEventArgs<IMainNavigationViewModel>>
{ {
-5
View File
@@ -1,5 +1,4 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Toolkit.Foundation; using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
@@ -13,8 +12,4 @@ public partial class BackActionViewModel(IServiceProvider provider,
{ {
[ObservableProperty] [ObservableProperty]
private int index = 0; private int index = 0;
[RelayCommand]
public void Invoke() => Publisher.Publish(Notify.As(new Search(Value)),
nameof(ItemCollectionViewModel));
} }
+1 -1
View File
@@ -13,5 +13,5 @@ public partial class ConfirmItemActionViewModel(IServiceProvider provider,
{ {
[RelayCommand] [RelayCommand]
public void Invoke() => Publisher.Publish(Confirm.As<Item>(), public void Invoke() => Publisher.Publish(Confirm.As<Item>(),
state is ItemState.New ? nameof(Create) : nameof(Update)); state is ItemState.New ? nameof(ItemState.New) : nameof(ItemState.Write));
} }
+8 -12
View File
@@ -7,10 +7,11 @@ namespace Bitvault;
[Notification(typeof(CreateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))] [Notification(typeof(CreateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
[Notification(typeof(InsertEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))] [Notification(typeof(InsertEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
[Notification(typeof(MoveToEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))] [Notification(typeof(MoveToEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
[Notification(typeof(NotifyEventArgs<Search<string>>), nameof(ItemCollectionViewModel))]
public partial class ItemCollectionViewModel : public partial class ItemCollectionViewModel :
ObservableCollection<ItemNavigationViewModel>, ObservableCollection<ItemNavigationViewModel>,
INotificationHandler<NotifyEventArgs<Filter>>, INotificationHandler<NotifyEventArgs<Filter>>,
INotificationHandler<NotifyEventArgs<Search>>, INotificationHandler<NotifyEventArgs<Search<string>>>,
IBackStack IBackStack
{ {
[ObservableProperty] [ObservableProperty]
@@ -42,18 +43,18 @@ public partial class ItemCollectionViewModel :
if (args.Value is Filter filter) if (args.Value is Filter filter)
{ {
configuration = configuration with { Filter = filter.Value }; configuration = configuration with { Filter = filter.Value };
BeginAggregation(); Fetch(true);
} }
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Handle(NotifyEventArgs<Search> args) public Task Handle(NotifyEventArgs<Search<string>> args)
{ {
if (args.Value is Search search) if (args.Value is Search<string> search)
{ {
configuration = configuration with { Query = search.Value }; configuration = configuration with { Query = search.Value };
BeginAggregation(); Fetch(true);
} }
return Task.CompletedTask; return Task.CompletedTask;
@@ -70,11 +71,6 @@ public partial class ItemCollectionViewModel :
return base.OnActivated(); return base.OnActivated();
} }
public override Task OnDeactivated() protected override AggregateExpression CreateAggregateExpression() =>
{ new(Aggregate.As<ItemNavigationViewModel, LockerViewModelConfiguration>(configuration));
return base.OnDeactivated();
}
protected override IAggerate OnAggerate(object? key) =>
Aggerate.With<ItemNavigationViewModel, LockerViewModelConfiguration>(configuration)
with { Key = key };
} }
-6
View File
@@ -21,12 +21,6 @@ public partial class ItemContentViewModel :
public IContentTemplate Template { get; set; } public IContentTemplate Template { get; set; }
protected override IAggerate OnAggerate(object? key)
{
return base.OnAggerate(key);
}
public Task Handle(NotifyEventArgs<ItemCategory<string>> args) public Task Handle(NotifyEventArgs<ItemCategory<string>> args)
{ {
return Task.CompletedTask; return Task.CompletedTask;
+2
View File
@@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using Toolkit.Foundation; using Toolkit.Foundation;
using Toolkit.UI.Avalonia;
namespace Bitvault; namespace Bitvault;
@@ -48,6 +49,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
private bool selected = selected; private bool selected = selected;
public IContentTemplate Template { get; set; } = template; public IContentTemplate Template { get; set; } = template;
public bool Attached { get; set; }
public Task Handle(ArchiveEventArgs<Item> args) => public Task Handle(ArchiveEventArgs<Item> args) =>
Task.Run(Dispose); Task.Run(Dispose);
+2 -2
View File
@@ -3,13 +3,13 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
[Notification(typeof(ConfirmEventArgs<Item>), nameof(Create))] [Notification(typeof(ConfirmEventArgs<Item>), nameof(ItemState.New))]
[Notification(typeof(ConfirmEventArgs<Item>), nameof(ItemState.Write))]
public partial class ItemViewModel : public partial class ItemViewModel :
ObservableCollection<IItemEntryViewModel>, ObservableCollection<IItemEntryViewModel>,
INotificationHandler<UpdateEventArgs<Item>>, INotificationHandler<UpdateEventArgs<Item>>,
INotificationHandler<ConfirmEventArgs<Item>>, INotificationHandler<ConfirmEventArgs<Item>>,
INotificationHandler<CancelEventArgs<Item>> INotificationHandler<CancelEventArgs<Item>>
{ {
[ObservableProperty] [ObservableProperty]
private bool archived; private bool archived;
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Bitvault; namespace Bitvault;
public record Search(string? Value); public record Search<TValue>(TValue? Value);
+1 -1
View File
@@ -15,6 +15,6 @@ public partial class SearchLockerActionViewModel(IServiceProvider provider,
private int index = 2; private int index = 2;
[RelayCommand] [RelayCommand]
public void Invoke() => Publisher.Publish(Notify.As(new Search(Value)), public void Invoke() => Publisher.Publish(Notify.As(new Search<string>(Value)),
nameof(ItemCollectionViewModel)); nameof(ItemCollectionViewModel));
} }