diff --git a/Wallet/CommentEntryCollectionViewModel.cs b/Wallet/CommentEntryCollectionViewModel.cs index d35ece9..69c0320 100644 --- a/Wallet/CommentEntryCollectionViewModel.cs +++ b/Wallet/CommentEntryCollectionViewModel.cs @@ -30,5 +30,17 @@ public partial class CommentEntryCollectionViewModel(IServiceProvider provider, return Task.CompletedTask; } + + protected override void OnStateChanged() + { + if (State is ItemState.Write) + { + Add(); + } + else + { + RemoveAt(Count - 1); + } + } } diff --git a/Wallet/CommentEntryCollectionViewModelHandler.cs b/Wallet/CommentEntryCollectionViewModelHandler.cs index 713e00f..c82514c 100644 --- a/Wallet/CommentEntryCollectionViewModelHandler.cs +++ b/Wallet/CommentEntryCollectionViewModelHandler.cs @@ -11,15 +11,18 @@ public class CommentEntryCollectionViewModelHandler(IServiceFactory serviceFacto if (args.Sender is CommentEntryCollectionConfiguration configuration) { string? label = configuration.Label; - List value = new List(); + List values = configuration.Value is not null ? new List(configuration.Value) : []; double? width = configuration.Width; if (serviceFactory.Create(args => args.Initialize(), - [.. args.Parameters, configuration, label, value, false, false, width]) + [.. args.Parameters, configuration, label, values, false, false, width]) is CommentEntryCollectionViewModel viewModel) { + foreach (Comment value in values.OrderByDescending(x => x.DateTime)) + { + viewModel.Add(value.DateTime, value.Text); + } - viewModel.Add(); return Task.FromResult(viewModel); } } diff --git a/Wallet/ItemEntryCollectionViewModel.cs b/Wallet/ItemEntryCollectionViewModel.cs index 726f1a7..0379e5e 100644 --- a/Wallet/ItemEntryCollectionViewModel.cs +++ b/Wallet/ItemEntryCollectionViewModel.cs @@ -77,22 +77,36 @@ public partial class ItemEntryCollectionViewModel : Track(nameof(Value), () => Value, x => Value = x); } - public Task Handle(UpdateEventArgs args) => - Task.FromResult(State = ItemState.Write); + public Task Handle(UpdateEventArgs args) + { + State = ItemState.Write; + OnStateChanged(); + + return Task.CompletedTask; + } public Task Handle(CancelEventArgs args) { Revert(); State = ItemState.Read; + OnStateChanged(); + return Task.CompletedTask; } + protected virtual void OnStateChanged() + { + + } + public Task Handle(ConfirmEventArgs args) { Commit(); State = ItemState.Read; + OnStateChanged(); + return Task.CompletedTask; }