Ensure we have value reverting working in the itementries

This commit is contained in:
TheXamlGuy
2024-07-12 23:33:21 +01:00
parent 767f9db286
commit 902d7e4659
3 changed files with 69 additions and 46 deletions
+2
View File
@@ -11,6 +11,8 @@ public class DropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
if (args.Sender is DropdownEntryConfiguration configuration) if (args.Sender is DropdownEntryConfiguration configuration)
{ {
List<DropdownValueViewModel> values = []; List<DropdownValueViewModel> values = [];
values.Add(serviceFactory.Create<DropdownValueViewModel>());
foreach (string item in configuration.Values) foreach (string item in configuration.Values)
{ {
values.Add(serviceFactory.Create<DropdownValueViewModel>(item)); values.Add(serviceFactory.Create<DropdownValueViewModel>(item));
+25 -23
View File
@@ -13,10 +13,18 @@ public partial class ItemEntryCollectionViewModel<TItem> :
where TItem : notnull, where TItem : notnull,
IDisposable IDisposable
{ {
private readonly ItemEntryConfiguration configuration;
[ObservableProperty]
private bool isConcealed;
[ObservableProperty]
private bool isRevealed;
[ObservableProperty] [ObservableProperty]
private ItemState state; private ItemState state;
[ObservableProperty]
private readonly ItemEntryConfiguration configuration; private double width;
public ItemEntryCollectionViewModel(IServiceProvider provider, public ItemEntryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory, IServiceFactory factory,
@@ -38,19 +46,10 @@ public partial class ItemEntryCollectionViewModel<TItem> :
IsConcealed = isConcealed; IsConcealed = isConcealed;
IsRevealed = isRevealed; IsRevealed = isRevealed;
Width = width; 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, public ItemEntryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory, IServiceFactory factory,
IMediator mediator, IMediator mediator,
@@ -69,15 +68,11 @@ public partial class ItemEntryCollectionViewModel<TItem> :
this.configuration = configuration; this.configuration = configuration;
State = state; State = state;
IsConcealed = isConcealed;
IsRevealed = isRevealed;
Width = width; Width = width;
}
protected override void OnValueChanged() Track(nameof(Value), () => Value, x => Value = x);
{
if (configuration is not null)
{
configuration.Value = Value;
}
} }
public Task Handle(UpdateEventArgs<Item> args) => public Task Handle(UpdateEventArgs<Item> args) =>
@@ -99,13 +94,20 @@ public partial class ItemEntryCollectionViewModel<TItem> :
return Task.CompletedTask; 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<object>($"{Value}")));
[RelayCommand] [RelayCommand]
private void Hide() => IsRevealed = false; private void Hide() => IsRevealed = false;
[RelayCommand] [RelayCommand]
private void Reveal() => IsRevealed = true; private void Reveal() => IsRevealed = true;
[RelayCommand]
private void Copy() => Publisher.Publish(Write.As(new Clipboard<object>($"{Value}")));
} }
+33 -14
View File
@@ -4,7 +4,15 @@ using Toolkit.Foundation;
namespace Wallet; namespace Wallet;
public partial class ItemEntryViewModel<TValue>(IServiceProvider provider, public partial class ItemEntryViewModel<TValue> :
Observable<string, TValue>,
IItemEntryViewModel,
INotificationHandler<ConfirmEventArgs<ItemEntry>>,
INotificationHandler<UpdateEventArgs<ItemEntry>>,
INotificationHandler<CancelEventArgs<ItemEntry>>
where TValue : notnull
{
public ItemEntryViewModel(IServiceProvider provider,
IServiceFactory factory, IServiceFactory factory,
IMediator mediator, IMediator mediator,
IPublisher publisher, IPublisher publisher,
@@ -16,25 +24,31 @@ public partial class ItemEntryViewModel<TValue>(IServiceProvider provider,
TValue value, TValue value,
bool isConcealed, bool isConcealed,
bool isRevealed, bool isRevealed,
double width) : double width) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
Observable<string, TValue>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
IItemEntryViewModel,
INotificationHandler<ConfirmEventArgs<ItemEntry>>,
INotificationHandler<UpdateEventArgs<ItemEntry>>,
INotificationHandler<CancelEventArgs<ItemEntry>>
where TValue : notnull
{ {
[ObservableProperty] this.configuration = configuration;
private bool isConcealed = isConcealed;
State = state;
IsConcealed = isConcealed;
IsRevealed = isRevealed;
Width = width;
Track(nameof(Value), () => Value, x => Value = x);
}
private readonly ItemEntryConfiguration configuration;
[ObservableProperty] [ObservableProperty]
private bool isRevealed = isRevealed; private bool isConcealed;
[ObservableProperty] [ObservableProperty]
private ItemState state = state; private bool isRevealed;
[ObservableProperty] [ObservableProperty]
private double width = width; private ItemState state;
[ObservableProperty]
private double width;
public Task Handle(UpdateEventArgs<ItemEntry> args) => public Task Handle(UpdateEventArgs<ItemEntry> args) =>
Task.FromResult(State = ItemState.Write); Task.FromResult(State = ItemState.Write);
@@ -55,8 +69,13 @@ public partial class ItemEntryViewModel<TValue>(IServiceProvider provider,
return Task.CompletedTask; return Task.CompletedTask;
} }
protected override void OnValueChanged() => protected override void OnValueChanged()
{
if (configuration is not null)
{
configuration.Value = Value; configuration.Value = Value;
}
}
[RelayCommand] [RelayCommand]
private void Hide() => IsRevealed = false; private void Hide() => IsRevealed = false;