diff --git a/Wallet.Avalonia/AllNavigationView.axaml b/Wallet.Avalonia/AllNavigationView.axaml index a47fa03..01a4060 100644 --- a/Wallet.Avalonia/AllNavigationView.axaml +++ b/Wallet.Avalonia/AllNavigationView.axaml @@ -24,7 +24,7 @@ - + diff --git a/Wallet.Avalonia/App.axaml.cs b/Wallet.Avalonia/App.axaml.cs index cf0553d..b9a2d4e 100644 --- a/Wallet.Avalonia/App.axaml.cs +++ b/Wallet.Avalonia/App.axaml.cs @@ -120,12 +120,12 @@ public partial class App : Application services.AddTemplate("OpenWallet"); - services.AddScoped(); + services.AddScoped(); services.AddTemplate("Wallet"); - services.AddTemplate("ContentItemCollection"); + services.AddTemplate("ItemCollection"); - services.AddHandler(); + services.AddHandler(); services.AddTemplate("WalletHeader"); services.AddTemplate(); @@ -146,9 +146,12 @@ public partial class App : Application services.AddTemplate(); services.AddTemplate("EmptyItemCollection"); + services.AddScoped, DecoratorService>(); services.AddScoped, DecoratorService>(); services.AddTemplate("Item"); + services.AddHandler("Item"); + services.AddTemplate(); services.AddTemplate(); diff --git a/Wallet.Avalonia/ArchiveNavigationView.axaml b/Wallet.Avalonia/ArchiveNavigationView.axaml index 34fd8c6..2e1d431 100644 --- a/Wallet.Avalonia/ArchiveNavigationView.axaml +++ b/Wallet.Avalonia/ArchiveNavigationView.axaml @@ -24,7 +24,7 @@ - + diff --git a/Wallet.Avalonia/CategoriesNavigationView.axaml b/Wallet.Avalonia/CategoriesNavigationView.axaml index 8a66282..196962b 100644 --- a/Wallet.Avalonia/CategoriesNavigationView.axaml +++ b/Wallet.Avalonia/CategoriesNavigationView.axaml @@ -5,4 +5,5 @@ xmlns:vm="using:Wallet" x:DataType="vm:CategoriesNavigationViewModel" Content="Categories" - MenuItemsSource="{Binding}" /> + MenuItemsSource="{Binding}" + SelectsOnInvoked="False" /> diff --git a/Wallet.Avalonia/CategoryNavigationView.axaml b/Wallet.Avalonia/CategoryNavigationView.axaml index cbc5d93..9b5efcf 100644 --- a/Wallet.Avalonia/CategoryNavigationView.axaml +++ b/Wallet.Avalonia/CategoryNavigationView.axaml @@ -4,4 +4,32 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="using:Wallet" x:DataType="vm:CategoryNavigationViewModel" - Content="{Binding Filter}" /> + Content="{Binding Filter}" + IsSelected="{Binding Selected}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wallet.Avalonia/ItemNavigationView.axaml b/Wallet.Avalonia/ItemNavigationView.axaml index db43cea..0289e25 100644 --- a/Wallet.Avalonia/ItemNavigationView.axaml +++ b/Wallet.Avalonia/ItemNavigationView.axaml @@ -14,11 +14,11 @@ Region="{Binding Named, StringFormat='{}{0}:Content'}" Route="Item" Scope="self"> - - + + diff --git a/Wallet.Avalonia/StarredNavigationView.axaml b/Wallet.Avalonia/StarredNavigationView.axaml index 8cd98dd..3525dc0 100644 --- a/Wallet.Avalonia/StarredNavigationView.axaml +++ b/Wallet.Avalonia/StarredNavigationView.axaml @@ -24,7 +24,7 @@ - + diff --git a/Wallet.Avalonia/WalletView.axaml b/Wallet.Avalonia/WalletView.axaml index f6ab203..f6e7dcd 100644 --- a/Wallet.Avalonia/WalletView.axaml +++ b/Wallet.Avalonia/WalletView.axaml @@ -26,7 +26,7 @@ - + diff --git a/Wallet/ConfirmCreateItemHandler.cs b/Wallet/ConfirmCreateItemHandler.cs index ec45d3f..a987ed7 100644 --- a/Wallet/ConfirmCreateItemHandler.cs +++ b/Wallet/ConfirmCreateItemHandler.cs @@ -4,21 +4,24 @@ namespace Wallet; public class ConfirmCreateItemHandler(IMediator mediator, IDecoratorService itemConfigurationDecorator, + IDecoratorService itemHeaderConfiguration, IPublisher publisher) : INotificationHandler> { public async Task Handle(ConfirmEventArgs args) { - if (itemConfigurationDecorator.Service is ItemConfiguration configuration) + if (itemHeaderConfiguration.Service is ItemHeaderConfiguration headerConfiguration && + itemConfigurationDecorator.Service is ItemConfiguration itemConfiguration) { - string? name = await mediator.Handle, string>(Confirm.As()); + string? name = headerConfiguration?.Name; if (name is not null) { Guid id = Guid.NewGuid(); publisher.Publish(Created.As(new Item<(Guid, string)>((id, name)))); await mediator.Handle, bool>(new CreateEventArgs<(Guid, string, string, ItemConfiguration)>((id, name, "", configuration))); + ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string, + ItemConfiguration)>((id, name, "", itemConfiguration))); } } } diff --git a/Wallet/ConfirmUpdateItemHandler.cs b/Wallet/ConfirmUpdateItemHandler.cs index 973afc9..1791a2b 100644 --- a/Wallet/ConfirmUpdateItemHandler.cs +++ b/Wallet/ConfirmUpdateItemHandler.cs @@ -4,18 +4,18 @@ namespace Wallet; public class ConfirmUpdateItemHandler(IDecoratorService> itemDecorator, IDecoratorService itemConfigurationDecorator, + IDecoratorService itemHeaderConfiguration, IMediator mediator, IPublisher publisher) : INotificationHandler> { public async Task Handle(ConfirmEventArgs args) { - if (itemDecorator?.Service is Item<(Guid, string)> item && - itemConfigurationDecorator.Service is ItemConfiguration configuration) + if (itemDecorator?.Service is Item<(Guid, string)> item && + itemHeaderConfiguration.Service is ItemHeaderConfiguration headerConfiguration && + itemConfigurationDecorator.Service is ItemConfiguration itemConfiguration) { - string? name = await mediator.Handle, - string>(Confirm.As()); - + string? name = headerConfiguration?.Name; if (name is not null) { publisher.Publish(Notify.As(new ItemHeader(name))); @@ -28,7 +28,7 @@ public class ConfirmUpdateItemHandler(IDecoratorService> it itemDecorator.Set(newItem); await mediator.Handle>, bool>(new UpdateEventArgs>(new Item<(Guid, string, ItemConfiguration)>((id, name, configuration)))); + ItemConfiguration)>>(new Item<(Guid, string, ItemConfiguration)>((id, name, itemConfiguration)))); } } } diff --git a/Wallet/CreateItemHandler.cs b/Wallet/CreateItemHandler.cs index 966ae37..b8c3766 100644 --- a/Wallet/CreateItemHandler.cs +++ b/Wallet/CreateItemHandler.cs @@ -13,7 +13,7 @@ public class CreateItemHandler(IDbContextFactory dbContextFactory public async Task Handle(CreateEventArgs<(Guid, string, string, ItemConfiguration)> args, CancellationToken cancellationToken) { - if (args.Value is (Guid id, string name, string category, ItemConfiguration configuration)) + if (args.Sender is (Guid id, string name, string category, ItemConfiguration configuration)) { try { diff --git a/Wallet/CreateItemViewModelHandler.cs b/Wallet/CreateItemViewModelHandler.cs new file mode 100644 index 0000000..78a0b0d --- /dev/null +++ b/Wallet/CreateItemViewModelHandler.cs @@ -0,0 +1,43 @@ +using System.Xml.Linq; +using Toolkit.Foundation; + +namespace Wallet; + +public class CreateItemViewModelHandler(IServiceFactory serviceFactory, + IDecoratorService itemHeaderConfigurationDecorator) : + IHandler, ItemViewModel?> +{ + public Task Handle(CreateEventArgs args, + CancellationToken cancellationToken) + { + string? name = ""; + ItemState? state = null; + + if (args.Parameters is { Length: 5 }) + { + (name, bool _, bool _, bool _, state) = args.Parameters.CreateValueTuple(); + } + + if (args.Parameters is { Length: 2 }) + { + (bool _, state) = args.Parameters.CreateValueTuple(); + } + + ItemHeaderConfiguration configuration = new() + { + Name = name + }; + + itemHeaderConfigurationDecorator.Set(configuration); + + if (serviceFactory.Create(args.Parameters) is ItemViewModel itemViewModel) + { + itemViewModel.Add(configuration, state, "", name); + itemViewModel.Add(); + + return Task.FromResult(itemViewModel); + } + + return Task.FromResult(default(ItemViewModel)); + } +} diff --git a/Wallet/CreateWalletHandler.cs b/Wallet/CreateWalletHandler.cs index abd5e3e..223df36 100644 --- a/Wallet/CreateWalletHandler.cs +++ b/Wallet/CreateWalletHandler.cs @@ -12,7 +12,7 @@ public class CreateWalletHandler(IWalletFactory componentFactory, public async Task Handle(CreateEventArgs> args, CancellationToken cancellationToken) { - if (args.Value is Wallet <(string, string)> Wallet) + if (args.Sender is Wallet <(string, string)> Wallet) { if (Wallet.Value is (string name, string password) && name is { Length: > 0 } && diff --git a/Wallet/DateEntryViewModelHandler.cs b/Wallet/DateEntryViewModelHandler.cs index 1dc034e..b32d637 100644 --- a/Wallet/DateEntryViewModelHandler.cs +++ b/Wallet/DateEntryViewModelHandler.cs @@ -8,7 +8,7 @@ public class DateEntryViewModelHandler(IServiceFactory serviceFactory) : public Task Handle(CreateEventArgs args, CancellationToken cancellationToken) { - if (args.Value is DateEntryConfiguration configuration) + if (args.Sender is DateEntryConfiguration configuration) { string? label = configuration.Label; diff --git a/Wallet/DropdownEntryViewModelHandler.cs b/Wallet/DropdownEntryViewModelHandler.cs index 1064177..45158f4 100644 --- a/Wallet/DropdownEntryViewModelHandler.cs +++ b/Wallet/DropdownEntryViewModelHandler.cs @@ -8,7 +8,7 @@ public class DropdownEntryViewModelHandler(IServiceFactory serviceFactory) : public Task Handle(CreateEventArgs args, CancellationToken cancellationToken) { - if (args.Value is DropdownEntryConfiguration configuration) + if (args.Sender is DropdownEntryConfiguration configuration) { List values = []; foreach (string item in configuration.Values) diff --git a/Wallet/FilterNavigationViewModel.cs b/Wallet/FilterNavigationViewModel.cs index 0897b18..29e00a3 100644 --- a/Wallet/FilterNavigationViewModel.cs +++ b/Wallet/FilterNavigationViewModel.cs @@ -1,5 +1,4 @@ using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; using Toolkit.Foundation; namespace Wallet; @@ -35,10 +34,6 @@ public partial class FilterNavigationViewModel : public Task Handle(ActivatedEventArgs args) => Task.FromResult(Activated = true); - - [RelayCommand] - public void Invoke() => Publisher.Publish(Notify.As(new Filter(Filter)), - nameof(ItemCollectionViewModel)); } public partial class FilterNavigationViewModel : @@ -46,7 +41,8 @@ public partial class FilterNavigationViewModel : IWalletNavigationViewModel, INotificationHandler>, INotificationHandler> - where TWalletNavigation : IWalletNavigationViewModel + where TWalletNavigation : + IWalletNavigationViewModel { [ObservableProperty] private bool activated; @@ -73,8 +69,4 @@ public partial class FilterNavigationViewModel : public Task Handle(ActivatedEventArgs args) => Task.FromResult(Activated = true); - - [RelayCommand] - public void Invoke() => Publisher.Publish(Notify.As(new Filter(Filter)), - nameof(ItemCollectionViewModel)); } \ No newline at end of file diff --git a/Wallet/IItemViewModel.cs b/Wallet/IItemViewModel.cs new file mode 100644 index 0000000..638902a --- /dev/null +++ b/Wallet/IItemViewModel.cs @@ -0,0 +1,7 @@ +namespace Wallet; + +public interface IItemViewModel : + IDisposable +{ + +} diff --git a/Wallet/WalletViewModelConfiguration.cs b/Wallet/ItemCollectionConfiguration.cs similarity index 72% rename from Wallet/WalletViewModelConfiguration.cs rename to Wallet/ItemCollectionConfiguration.cs index 6bb0599..fd9b854 100644 --- a/Wallet/WalletViewModelConfiguration.cs +++ b/Wallet/ItemCollectionConfiguration.cs @@ -1,6 +1,6 @@ namespace Wallet; -public record WalletViewModelConfiguration +public record ItemCollectionConfiguration { public string? Filter { get; set; } = "All"; diff --git a/Wallet/ItemCollectionViewModel.cs b/Wallet/ItemCollectionViewModel.cs index 9ec73d0..84ae3a1 100644 --- a/Wallet/ItemCollectionViewModel.cs +++ b/Wallet/ItemCollectionViewModel.cs @@ -16,7 +16,7 @@ public partial class ItemCollectionViewModel : [ObservableProperty] public string? named; - private WalletViewModelConfiguration configuration; + private ItemCollectionConfiguration configuration; public ItemCollectionViewModel(IServiceProvider provider, IServiceFactory factory, @@ -26,7 +26,7 @@ public partial class ItemCollectionViewModel : IDisposer disposer, IContentTemplate template, NamedComponent named, - WalletViewModelConfiguration configuration, + ItemCollectionConfiguration configuration, string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer) { Template = template; @@ -39,7 +39,7 @@ public partial class ItemCollectionViewModel : public Task Handle(NotifyEventArgs args) { - if (args.Value is Filter filter) + if (args.Sender is Filter filter) { configuration = configuration with { Filter = filter.Value }; Fetch(true); @@ -50,7 +50,7 @@ public partial class ItemCollectionViewModel : public Task Handle(NotifyEventArgs> args) { - if (args.Value is Search search) + if (args.Sender is Search search) { configuration = configuration with { Query = search.Value }; Fetch(true); @@ -71,5 +71,5 @@ public partial class ItemCollectionViewModel : } protected override SynchronizeExpression BuildAggregateExpression() => - new(Synchronize.As(configuration)); + new(Synchronize.As(configuration)); } diff --git a/Wallet/ItemCommandHeaderViewModel.cs b/Wallet/ItemCommandHeaderViewModel.cs index 96dbe77..27403c1 100644 --- a/Wallet/ItemCommandHeaderViewModel.cs +++ b/Wallet/ItemCommandHeaderViewModel.cs @@ -16,16 +16,17 @@ public partial class ItemCommandHeaderViewModel(IServiceProvider provider, public Task Handle(NotifyEventArgs args) { - Clear(); - - if (args.Value is ItemCommandHeaderCollection commandCollection) + if (args.Sender is ItemCommandHeaderCollection commandCollection) { - foreach (IDisposable command in commandCollection) + Clear(args => { - Add(command); - } + foreach (IDisposable command in commandCollection) + { + args.Add(command); + } + }); } - + return Task.CompletedTask; } } \ No newline at end of file diff --git a/Wallet/ItemContentViewModel.cs b/Wallet/ItemContentViewModel.cs index eb91ff8..53c001e 100644 --- a/Wallet/ItemContentViewModel.cs +++ b/Wallet/ItemContentViewModel.cs @@ -11,18 +11,18 @@ public partial class ItemContentViewModel(IServiceProvider provider, IContentTemplate template) : ObservableCollection(provider, factory, mediator, publisher, subscriber, disposer), IItemEntryViewModel, - INotificationHandler>> + INotificationHandler>>, + IItemViewModel { public IContentTemplate Template { get; set; } = template; public Task Handle(NotifyEventArgs> args) { - if (args.Value is ItemCategory category) + if (args.Sender is ItemCategory category + && category.Value is string value) { - if (category.Value is string value) - { - Fetch(() => new SynchronizeExpression(new SynchronizeEventArgs(value)), true); - } + Fetch(() => new SynchronizeExpression(new SynchronizeEventArgs(value)), true); } return Task.CompletedTask; diff --git a/Wallet/ItemCreatedHandler.cs b/Wallet/ItemCreatedHandler.cs index 621cc9c..2f15bc7 100644 --- a/Wallet/ItemCreatedHandler.cs +++ b/Wallet/ItemCreatedHandler.cs @@ -10,7 +10,7 @@ public class ItemCreatedHandler(IServiceProvider serviceProvider, { public Task Handle(CreatedEventArgs> args) { - if (args.Value is Item<(Guid, string)> item) + if (args.Sender is Item<(Guid, string)> item) { (Guid id, string name) = item.Value; diff --git a/Wallet/ItemHeader.cs b/Wallet/ItemHeader.cs index 7276eda..43ad3f0 100644 --- a/Wallet/ItemHeader.cs +++ b/Wallet/ItemHeader.cs @@ -2,4 +2,4 @@ public record ItemHeader(TValue Value); -public record ItemHeader; \ No newline at end of file +public record ItemHeader; diff --git a/Wallet/ItemHeaderConfiguration.cs b/Wallet/ItemHeaderConfiguration.cs new file mode 100644 index 0000000..917e20b --- /dev/null +++ b/Wallet/ItemHeaderConfiguration.cs @@ -0,0 +1,6 @@ +namespace Wallet; + +public class ItemHeaderConfiguration +{ + public string? Name { get; set; } +} \ No newline at end of file diff --git a/Wallet/ItemHeaderViewModel.cs b/Wallet/ItemHeaderViewModel.cs index d424c84..d03ff5e 100644 --- a/Wallet/ItemHeaderViewModel.cs +++ b/Wallet/ItemHeaderViewModel.cs @@ -8,10 +8,11 @@ public partial class ItemHeaderViewModel : INotificationHandler>, INotificationHandler>, INotificationHandler>, - IHandler, bool>, - IHandler, string?>, - INotificationHandler>> + INotificationHandler>>, + IItemViewModel { + private readonly ItemHeaderConfiguration configuration; + [ObservableProperty] private string? category; @@ -24,22 +25,19 @@ public partial class ItemHeaderViewModel : IPublisher publisher, ISubscription subscriber, IDisposer disposer, + ItemHeaderConfiguration configuration, ItemState state, string key, string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value) { + this.configuration = configuration; + State = state; Value = value; Track(nameof(Value), () => Value, newValue => Value = newValue); } - public Task Handle(ValidationEventArgs args, - CancellationToken cancellationToken) - { - return Task.FromResult(true); - } - public Task Handle(UpdateEventArgs args) => Task.FromResult(State = ItemState.Write); @@ -51,6 +49,14 @@ public partial class ItemHeaderViewModel : return Task.CompletedTask; } + protected override void OnValueChanged() + { + if (configuration is not null) + { + configuration.Name = Value; + } + } + public Task Handle(ConfirmEventArgs args) { Commit(); @@ -61,14 +67,11 @@ public partial class ItemHeaderViewModel : public Task Handle(NotifyEventArgs> args) { - if (args.Value is ItemCategory category) + if (args.Sender is ItemCategory category) { Category = category.Value; } return Task.CompletedTask; } - - public Task Handle(ConfirmEventArgs args, - CancellationToken cancellationToken) => Task.FromResult(Value); } \ No newline at end of file diff --git a/Wallet/ItemNavigationViewModel.cs b/Wallet/ItemNavigationViewModel.cs index 4bdd250..7d5abe5 100644 --- a/Wallet/ItemNavigationViewModel.cs +++ b/Wallet/ItemNavigationViewModel.cs @@ -68,7 +68,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider, public Task Handle(NotifyEventArgs> args) { - if (args.Value is ItemHeader header) + if (args.Sender is ItemHeader header) { Name = header.Value; } diff --git a/Wallet/ItemViewModel.cs b/Wallet/ItemViewModel.cs index b993af4..a500dea 100644 --- a/Wallet/ItemViewModel.cs +++ b/Wallet/ItemViewModel.cs @@ -4,7 +4,7 @@ using Toolkit.Foundation; namespace Wallet; public partial class ItemViewModel : - ObservableCollection, + ObservableCollection, INotificationHandler>, INotificationHandler>, INotificationHandler> @@ -16,16 +16,16 @@ public partial class ItemViewModel : private bool favourite; [ObservableProperty] - private ItemState state; - - [ObservableProperty] - private string named; + private bool fromCategory; [ObservableProperty] private string name; [ObservableProperty] - private bool fromCategory; + private string named; + + [ObservableProperty] + private ItemState state; public ItemViewModel(IServiceProvider provider, IServiceFactory factory, @@ -35,11 +35,11 @@ public partial class ItemViewModel : IDisposer disposer, IContentTemplate template, NamedComponent named, - ItemState state = ItemState.Read, - bool fromCategory = false, string name = "", + bool fromCategory = false, bool favourite = false, - bool archived = false) : base(provider, factory, mediator, publisher, subscriber, disposer) + bool archived = false, + ItemState state = ItemState.Read) : base(provider, factory, mediator, publisher, subscriber, disposer) { Template = template; Named = $"{named}"; @@ -48,13 +48,19 @@ public partial class ItemViewModel : Favourite = favourite; Archived = archived; Name = name; - - Add("", name, state); - Add(); } public IContentTemplate Template { get; set; } + public override void Dispose() + { + GC.SuppressFinalize(this); + Publisher.Publish(Notify.As(Factory.Create(new + List()))); + + base.Dispose(); + } + public Task Handle(UpdateEventArgs args) { Publisher.Publish(Notify.As(Factory.Create(new List @@ -67,14 +73,6 @@ public partial class ItemViewModel : return Task.CompletedTask; } - public override void Dispose() - { - Publisher.Publish(Notify.As(Factory.Create(new - List()))); - - base.Dispose(); - } - public Task Handle(CancelEventArgs args) { Publisher.Publish(Notify.As(Factory.Create(new List @@ -95,7 +93,7 @@ public partial class ItemViewModel : Factory.Create(), Factory.Create(), }))); - + Publisher.Publish(Confirm.As(), State is ItemState.New ? nameof(ItemState.New) : nameof(ItemState.Write)); @@ -135,4 +133,7 @@ public partial class ItemViewModel : return base.OnActivated(); } + + protected override SynchronizeExpression BuildAggregateExpression() => + new(Synchronize.As(("", Name, State))); } \ No newline at end of file diff --git a/Wallet/MaskedTextEntryViewModelHandler.cs b/Wallet/MaskedTextEntryViewModelHandler.cs index d654359..de0b364 100644 --- a/Wallet/MaskedTextEntryViewModelHandler.cs +++ b/Wallet/MaskedTextEntryViewModelHandler.cs @@ -8,7 +8,7 @@ public class MaskedTextEntryViewModelHandler(IServiceFactory serviceFactory) : public Task Handle(CreateEventArgs args, CancellationToken cancellationToken) { - if (args.Value is MaskedTextEntryConfiguration configuration) + if (args.Sender is MaskedTextEntryConfiguration configuration) { string? label = configuration.Label; object? value = configuration.Value ?? ""; diff --git a/Wallet/MultilineTextEntryViewModelHandler.cs b/Wallet/MultilineTextEntryViewModelHandler.cs index 696b2f1..dc418bc 100644 --- a/Wallet/MultilineTextEntryViewModelHandler.cs +++ b/Wallet/MultilineTextEntryViewModelHandler.cs @@ -8,7 +8,7 @@ public class MultilineTextEntryViewModelHandler(IServiceFactory serviceFactory) public Task Handle(CreateEventArgs args, CancellationToken cancellationToken) { - if (args.Value is MultilineTextEntryConfiguration configuration) + if (args.Sender is MultilineTextEntryConfiguration configuration) { string? label = configuration.Label; object? value = configuration.Value ?? ""; diff --git a/Wallet/OpenWalletHandler.cs b/Wallet/OpenWalletHandler.cs index 3f31f31..d597c57 100644 --- a/Wallet/OpenWalletHandler.cs +++ b/Wallet/OpenWalletHandler.cs @@ -11,7 +11,7 @@ public class OpenWalletHandler(IConfigurationDescriptor des public async Task Handle(ActivateEventArgs> args, CancellationToken cancellationToken) { - if (args.Value is Wallet Wallet && + if (args.Sender is Wallet Wallet && descriptor.Name is { Length: > 0 } name && Wallet.Value is { Length: > 0 } password) { diff --git a/Wallet/PasswordEntryViewModelHandler.cs b/Wallet/PasswordEntryViewModelHandler.cs index 6a29fc2..d47a788 100644 --- a/Wallet/PasswordEntryViewModelHandler.cs +++ b/Wallet/PasswordEntryViewModelHandler.cs @@ -8,7 +8,7 @@ public class PasswordEntryViewModelHandler(IServiceFactory serviceFactory) : public Task Handle(CreateEventArgs args, CancellationToken cancellationToken) { - if (args.Value is PasswordEntryConfiguration configuration) + if (args.Sender is PasswordEntryConfiguration configuration) { string? label = configuration.Label; object? value = configuration.Value ?? ""; diff --git a/Wallet/QueryWalletHandler.cs b/Wallet/QueryWalletHandler.cs index 230f9f2..28f7bb9 100644 --- a/Wallet/QueryWalletHandler.cs +++ b/Wallet/QueryWalletHandler.cs @@ -19,20 +19,29 @@ public class QueryWalletHandler(IDbContextFactory dbContextFactor ExpressionStarter predicate = PredicateBuilder.New(true); + if (filter is { Length: <= 0 }) + { + return items; + } + if (filter == "All") { predicate = predicate.And(x => x.State != 2); } - - if (filter == "Starred") + else if (filter == "Starred") { predicate = predicate.And(x => x.State != 2 && x.State == 1); } - - if (filter == "Archive") + else if (filter == "Archive") { predicate = predicate.And(x => x.State == 2); } + else + { + predicate = predicate.And(x => x.State != 2) + .And(x => EF.Functions.Like(x.Category, $"%{filter}%")); + } + if (text is { Length: > 0 }) { diff --git a/Wallet/SynchronizeItemViewModelHandler.cs b/Wallet/SynchronizeItemCollectionViewModelHandler.cs similarity index 89% rename from Wallet/SynchronizeItemViewModelHandler.cs rename to Wallet/SynchronizeItemCollectionViewModelHandler.cs index da57595..2729534 100644 --- a/Wallet/SynchronizeItemViewModelHandler.cs +++ b/Wallet/SynchronizeItemCollectionViewModelHandler.cs @@ -3,16 +3,16 @@ using Toolkit.Foundation; namespace Wallet; -public class SynchronizeItemViewModelHandler(IMediator mediator, +public class SynchronizeItemCollectionViewModelHandler(IMediator mediator, IServiceProvider serviceProvider, ICache> cache, IPublisher publisher) : - INotificationHandler> + INotificationHandler> { public async Task Handle(SynchronizeEventArgs args) + ItemCollectionConfiguration> args) { - if (args.Value is WalletViewModelConfiguration configuration) + if (args.Value is ItemCollectionConfiguration configuration) { cache.Clear(); bool selected = true; diff --git a/Wallet/SynchronizeItemContentFromCategoryViewModelHandler.cs b/Wallet/SynchronizeItemContentFromCategoryViewModelHandler.cs index 85941e4..edbb999 100644 --- a/Wallet/SynchronizeItemContentFromCategoryViewModelHandler.cs +++ b/Wallet/SynchronizeItemContentFromCategoryViewModelHandler.cs @@ -4,7 +4,7 @@ using Toolkit.Foundation; namespace Wallet; public class SynchronizeItemContentFromCategoryViewModelHandler(IItemConfigurationCollection configurations, - IDecoratorService decoratorItemConfiguration, + IDecoratorService itemConfigurationDecorator, IServiceFactory serviceFactory, IMediator mediator, IPublisher publisher) : @@ -18,7 +18,7 @@ public class SynchronizeItemContentFromCategoryViewModelHandler(IItemConfigurati { if (configurationFactory.Invoke() is ItemConfiguration configuration) { - decoratorItemConfiguration.Set(configuration); + itemConfigurationDecorator.Set(configuration); foreach (ItemSectionConfiguration configurationSection in configuration.Sections) { string id = $"{nameof(ItemSection)}:{Guid.NewGuid()}"; diff --git a/Wallet/TextEntryViewModelHandler.cs b/Wallet/TextEntryViewModelHandler.cs index d0d1aab..5314d32 100644 --- a/Wallet/TextEntryViewModelHandler.cs +++ b/Wallet/TextEntryViewModelHandler.cs @@ -8,7 +8,7 @@ public class TextEntryViewModelHandler(IServiceFactory serviceFactory) : public Task Handle(CreateEventArgs args, CancellationToken cancellationToken) { - if (args.Value is TextEntryConfiguration configuration) + if (args.Sender is TextEntryConfiguration configuration) { string? label = configuration.Label; object? value = configuration.Value ?? ""; diff --git a/Wallet/WalletActivatedHandler.cs b/Wallet/WalletActivatedHandler.cs index a530333..5577510 100644 --- a/Wallet/WalletActivatedHandler.cs +++ b/Wallet/WalletActivatedHandler.cs @@ -9,7 +9,7 @@ public class WalletActivatedHandler(IWalletHostCollection Wallets, { public Task Handle(ActivatedEventArgs args) { - if (args.Value is IComponentHost Wallet) + if (args.Sender is IComponentHost Wallet) { List sortedWallets = [.. Wallets, Wallet]; sortedWallets = [.. sortedWallets.OrderBy(x => x.Services.GetRequiredService>() is diff --git a/Wallet/WalletHeaderViewModel.cs b/Wallet/WalletHeaderViewModel.cs index 69e3d4c..c21a94b 100644 --- a/Wallet/WalletHeaderViewModel.cs +++ b/Wallet/WalletHeaderViewModel.cs @@ -18,7 +18,7 @@ public partial class WalletHeaderViewModel(IServiceProvider provider, { Clear(); - if (args.Value is WalletCommandHeaderCollection commandCollection) + if (args.Sender is WalletCommandHeaderCollection commandCollection) { foreach (IDisposable command in commandCollection) {