Make it possible to remove enteries

This commit is contained in:
TheXamlGuy
2024-08-01 23:19:30 +01:00
parent 9e25f7ea60
commit 0c21ddd20d
8 changed files with 234 additions and 245 deletions
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Reactive.Disposables;
using System.Reflection;
using Toolkit.Foundation;
namespace Wallet;
@@ -7,6 +8,7 @@ public class ItemContentViewModelActivationHandler(IDecoratorService<Item<(Guid,
IDecoratorService<ItemConfiguration> itemConfigurationDecorator,
IMediator mediator,
IServiceFactory serviceFactory,
IDisposer disposer,
IPublisher publisher) :
INotificationHandler<ActivationEventArgs<ItemSectionViewModel>>
{
@@ -39,6 +41,12 @@ public class ItemContentViewModelActivationHandler(IDecoratorService<Item<(Guid,
if (await mediator.Handle<object, IItemEntryViewModel?>(message,
entryConfiguration.GetType().Name) is IItemEntryViewModel entryViewModel)
{
// Should this be here?
disposer.Add(entryViewModel, Disposable.Create(() =>
{
configurationSection.Entries.Remove(entryConfiguration);
}));
publisher.Publish(Create.As(entryViewModel), id);
}
}
+6
View File
@@ -7,6 +7,7 @@ namespace Wallet;
public partial class ItemEntryViewModel<TValue> :
Observable<string, TValue>,
IItemEntryViewModel,
IRemovable,
IHandler<ValidateEventArgs<ItemEntry>, bool>,
INotificationHandler<ConfirmEventArgs<ItemEntry>>,
INotificationHandler<UpdateEventArgs<ItemEntry>>,
@@ -69,6 +70,8 @@ public partial class ItemEntryViewModel<TValue> :
return Task.CompletedTask;
}
public async Task<bool> Handle(ValidateEventArgs<ItemEntry> args,
CancellationToken cancellationToken)
{
@@ -80,6 +83,9 @@ public partial class ItemEntryViewModel<TValue> :
return await Task.FromResult(true);
}
[RelayCommand]
private void Remove() => Dispose();
[RelayCommand]
private void Copy() => Publisher.Publish(Write.As(new Clipboard<object>($"{Value}")));