diff --git a/Wallet/DropdownEntryViewModelHandler.cs b/Wallet/DropdownEntryViewModelHandler.cs index f81ef0e..c552850 100644 --- a/Wallet/DropdownEntryViewModelHandler.cs +++ b/Wallet/DropdownEntryViewModelHandler.cs @@ -11,6 +11,8 @@ public class DropdownEntryViewModelHandler(IServiceFactory serviceFactory) : if (args.Sender is DropdownEntryConfiguration configuration) { List values = []; + values.Add(serviceFactory.Create()); + foreach (string item in configuration.Values) { values.Add(serviceFactory.Create(item)); diff --git a/Wallet/ItemEntryCollectionViewModel.cs b/Wallet/ItemEntryCollectionViewModel.cs index 5ee4355..b4758bc 100644 --- a/Wallet/ItemEntryCollectionViewModel.cs +++ b/Wallet/ItemEntryCollectionViewModel.cs @@ -13,12 +13,20 @@ public partial class ItemEntryCollectionViewModel : where TItem : notnull, IDisposable { - [ObservableProperty] - private ItemState state; - private readonly ItemEntryConfiguration configuration; - public ItemEntryCollectionViewModel(IServiceProvider provider, + [ObservableProperty] + private bool isConcealed; + + [ObservableProperty] + private bool isRevealed; + + [ObservableProperty] + private ItemState state; + [ObservableProperty] + private double width; + + public ItemEntryCollectionViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, @@ -38,19 +46,10 @@ public partial class ItemEntryCollectionViewModel : IsConcealed = isConcealed; IsRevealed = isRevealed; Width = width; + + Track(nameof(Value), () => Value, x => Value = x); } - [ObservableProperty] - private bool isConcealed; - - [ObservableProperty] - private bool isRevealed; - - - [ObservableProperty] - private double width; - - public ItemEntryCollectionViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, @@ -69,15 +68,11 @@ public partial class ItemEntryCollectionViewModel : this.configuration = configuration; State = state; + IsConcealed = isConcealed; + IsRevealed = isRevealed; Width = width; - } - protected override void OnValueChanged() - { - if (configuration is not null) - { - configuration.Value = Value; - } + Track(nameof(Value), () => Value, x => Value = x); } public Task Handle(UpdateEventArgs args) => @@ -99,13 +94,20 @@ public partial class ItemEntryCollectionViewModel : return Task.CompletedTask; } + protected override void OnValueChanged() + { + if (configuration is not null) + { + configuration.Value = Value; + } + } + + [RelayCommand] + private void Copy() => Publisher.Publish(Write.As(new Clipboard($"{Value}"))); [RelayCommand] private void Hide() => IsRevealed = false; [RelayCommand] private void Reveal() => IsRevealed = true; - - [RelayCommand] - private void Copy() => Publisher.Publish(Write.As(new Clipboard($"{Value}"))); } \ No newline at end of file diff --git a/Wallet/ItemEntryViewModel.cs b/Wallet/ItemEntryViewModel.cs index d7fdf8e..9de54f7 100644 --- a/Wallet/ItemEntryViewModel.cs +++ b/Wallet/ItemEntryViewModel.cs @@ -4,37 +4,51 @@ using Toolkit.Foundation; namespace Wallet; -public partial class ItemEntryViewModel(IServiceProvider provider, - IServiceFactory factory, - IMediator mediator, - IPublisher publisher, - ISubscriber subscriber, - IDisposer disposer, - ItemState state, - ItemEntryConfiguration configuration, - string key, - TValue value, - bool isConcealed, - bool isRevealed, - double width) : - Observable(provider, factory, mediator, publisher, subscriber, disposer, key, value), +public partial class ItemEntryViewModel : + Observable, IItemEntryViewModel, INotificationHandler>, INotificationHandler>, INotificationHandler> where TValue : notnull { - [ObservableProperty] - private bool isConcealed = isConcealed; + public ItemEntryViewModel(IServiceProvider provider, + IServiceFactory factory, + IMediator mediator, + IPublisher publisher, + ISubscriber subscriber, + IDisposer disposer, + ItemState state, + ItemEntryConfiguration configuration, + string key, + TValue value, + bool isConcealed, + bool isRevealed, + double width) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value) + { + this.configuration = configuration; + + State = state; + IsConcealed = isConcealed; + IsRevealed = isRevealed; + Width = width; + + Track(nameof(Value), () => Value, x => Value = x); + } + + private readonly ItemEntryConfiguration configuration; [ObservableProperty] - private bool isRevealed = isRevealed; + private bool isConcealed; [ObservableProperty] - private ItemState state = state; + private bool isRevealed; [ObservableProperty] - private double width = width; + private ItemState state; + + [ObservableProperty] + private double width; public Task Handle(UpdateEventArgs args) => Task.FromResult(State = ItemState.Write); @@ -55,8 +69,13 @@ public partial class ItemEntryViewModel(IServiceProvider provider, return Task.CompletedTask; } - protected override void OnValueChanged() => - configuration.Value = Value; + protected override void OnValueChanged() + { + if (configuration is not null) + { + configuration.Value = Value; + } + } [RelayCommand] private void Hide() => IsRevealed = false;