diff --git a/Toolkit b/Toolkit index 4a33a19..f993e1d 160000 --- a/Toolkit +++ b/Toolkit @@ -1 +1 @@ -Subproject commit 4a33a1931f68adc5f33e23f4a56c50b0c5b17c98 +Subproject commit f993e1d44b286ddba44b4f3578171b40d86f5177 diff --git a/Wallet.Avalonia/App.axaml.cs b/Wallet.Avalonia/App.axaml.cs index 8d2a5e3..cc80b97 100644 --- a/Wallet.Avalonia/App.axaml.cs +++ b/Wallet.Avalonia/App.axaml.cs @@ -105,6 +105,7 @@ public partial class App : Application services.AddHandler(); services.AddHandler(); services.AddHandler(); + services.AddHandler(); services.AddHandler(); services.AddHandler(); services.AddHandler(); @@ -181,7 +182,8 @@ public partial class App : Application services.AddHandler(nameof(ItemState.Write)); services.AddHandler(nameof(ItemState.New)); - + services.AddHandler(); + services.AddHandler(); services.AddHandler(ServiceLifetime.Singleton); diff --git a/Wallet.Avalonia/ArchiveItemActionView.axaml b/Wallet.Avalonia/ArchiveItemActionView.axaml index 3a27141..ce460f2 100644 --- a/Wallet.Avalonia/ArchiveItemActionView.axaml +++ b/Wallet.Avalonia/ArchiveItemActionView.axaml @@ -16,7 +16,7 @@ Margin="0,3,0,0" VerticalAlignment="Center" FontFamily="{DynamicResource FluentThemeFontFamily}" - FontSize="16" + FontSize="18" Foreground="{DynamicResource IconForegroundBrush}" Text="" /> diff --git a/Wallet.Avalonia/ConfirmItemActionView.axaml b/Wallet.Avalonia/ConfirmItemActionView.axaml index 5709e48..93b31d4 100644 --- a/Wallet.Avalonia/ConfirmItemActionView.axaml +++ b/Wallet.Avalonia/ConfirmItemActionView.axaml @@ -15,7 +15,7 @@ Margin="0,3,0,0" VerticalAlignment="Center" FontFamily="{DynamicResource FluentThemeFontFamily}" - FontSize="16" + FontSize="18" Foreground="{DynamicResource IconForegroundBrush}" Text="" /> diff --git a/Wallet.Avalonia/DeleteItemActionView.axaml b/Wallet.Avalonia/DeleteItemActionView.axaml index bcbc00b..3f59f04 100644 --- a/Wallet.Avalonia/DeleteItemActionView.axaml +++ b/Wallet.Avalonia/DeleteItemActionView.axaml @@ -14,9 +14,9 @@ + Text="" /> diff --git a/Wallet.Avalonia/DismissItemActionView.axaml b/Wallet.Avalonia/DismissItemActionView.axaml index ebbae31..78038b6 100644 --- a/Wallet.Avalonia/DismissItemActionView.axaml +++ b/Wallet.Avalonia/DismissItemActionView.axaml @@ -15,7 +15,7 @@ Margin="0,3,0,0" VerticalAlignment="Center" FontFamily="{DynamicResource FluentThemeFontFamily}" - FontSize="16" + FontSize="18" Foreground="{DynamicResource IconForegroundBrush}" Text="" /> diff --git a/Wallet.Avalonia/EditItemActionView.axaml b/Wallet.Avalonia/EditItemActionView.axaml index f48925d..212ffc4 100644 --- a/Wallet.Avalonia/EditItemActionView.axaml +++ b/Wallet.Avalonia/EditItemActionView.axaml @@ -15,7 +15,7 @@ Margin="0,3,0,0" VerticalAlignment="Center" FontFamily="{DynamicResource FluentThemeFontFamily}" - FontSize="16" + FontSize="18" Foreground="{DynamicResource IconForegroundBrush}" Text="" /> diff --git a/Wallet.Avalonia/FavouriteItemActionView.axaml b/Wallet.Avalonia/FavouriteItemActionView.axaml index 17e0cba..62cd12d 100644 --- a/Wallet.Avalonia/FavouriteItemActionView.axaml +++ b/Wallet.Avalonia/FavouriteItemActionView.axaml @@ -14,14 +14,14 @@ diff --git a/Wallet.Avalonia/ItemSectionView.axaml b/Wallet.Avalonia/ItemSectionView.axaml index f781299..df6ce06 100644 --- a/Wallet.Avalonia/ItemSectionView.axaml +++ b/Wallet.Avalonia/ItemSectionView.axaml @@ -5,6 +5,11 @@ xmlns:vm="using:Wallet" x:DataType="vm:ItemSectionViewModel"> + + + diff --git a/Wallet.Avalonia/ItemView.axaml b/Wallet.Avalonia/ItemView.axaml index ff60ec4..4b1cce7 100644 --- a/Wallet.Avalonia/ItemView.axaml +++ b/Wallet.Avalonia/ItemView.axaml @@ -2,8 +2,15 @@ x:Class="Wallet.Avalonia.ItemView" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:vm="using:Wallet" x:DataType="vm:ItemViewModel"> + + + + ToolTip.Tip="Restore"> + Text="" /> diff --git a/Wallet.Data/LockerContext.cs b/Wallet.Data/LockerContext.cs index 94aea17..7f2ee40 100644 --- a/Wallet.Data/LockerContext.cs +++ b/Wallet.Data/LockerContext.cs @@ -15,10 +15,12 @@ public class WalletContext(DbContextOptions options) : { modelBuilder.Entity() .HasMany(x => x.Tags) - .WithOne(); + .WithOne() + .OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity() .HasMany(x => x.Blobs) - .WithOne(); + .WithOne() + .OnDelete(DeleteBehavior.Cascade); } } \ No newline at end of file diff --git a/Wallet/ConfirmDeleteItemHandler.cs b/Wallet/ConfirmDeleteItemHandler.cs new file mode 100644 index 0000000..9581191 --- /dev/null +++ b/Wallet/ConfirmDeleteItemHandler.cs @@ -0,0 +1,30 @@ +using Toolkit.Foundation; + +namespace Wallet; + +public class ConfirmDeleteItemHandler(IDecoratorService> decoratorService, + ICache> cache, + IMediator mediator, + IPublisher publisher) : + INotificationHandler> +{ + public async Task Handle(DeleteEventArgs args) + { + try + { + if (decoratorService.Service is Item<(Guid, string)> item) + { + (Guid id, string name) = item.Value; + + await mediator.Handle>, + bool>(new DeleteEventArgs>(new Item(id))); + + cache.Add(item); + publisher.Publish(Changed.As()); + } + } + catch + { + } + } +} \ No newline at end of file diff --git a/Wallet/DeleteItemHandler.cs b/Wallet/DeleteItemHandler.cs new file mode 100644 index 0000000..3bdc87e --- /dev/null +++ b/Wallet/DeleteItemHandler.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; +using Toolkit.Foundation; +using Wallet.Data; + +namespace Wallet; + +public class DeleteItemHandler(IDbContextFactory dbContextFactory) : + IHandler>, bool> +{ + public async Task Handle(DeleteEventArgs> args, + CancellationToken cancellationToken) + { + if (args.Sender is Item item) + { + Guid id = item.Value; + + using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken); + if (await context.FindAsync(id) is ItemEntry result) + { + context.Items.Remove(result); + await context.SaveChangesAsync(cancellationToken); + } + } + return false; + } +} \ No newline at end of file diff --git a/Wallet/ItemNavigationViewModel.cs b/Wallet/ItemNavigationViewModel.cs index 5bcf900..3b5dc7c 100644 --- a/Wallet/ItemNavigationViewModel.cs +++ b/Wallet/ItemNavigationViewModel.cs @@ -23,6 +23,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider, INotificationHandler>, INotificationHandler>, INotificationHandler>, + INotificationHandler>, INotificationHandler>>, IKeyed, ISelectable, @@ -43,15 +44,14 @@ public partial class ItemNavigationViewModel(IServiceProvider provider, [ObservableProperty] private Guid id = id; + [ObservableProperty] + private bool isSelected = isSelected; + [ObservableProperty] private string? name = name; [ObservableProperty] private string named = $"{named}"; - - [ObservableProperty] - private bool isSelected = isSelected; - public IContentTemplate Template { get; set; } = template; public Task Handle(ArchiveEventArgs args) => @@ -75,4 +75,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider, return Task.CompletedTask; } + + public Task Handle(DeleteEventArgs args) => + Task.Run(Dispose); } \ No newline at end of file diff --git a/Wallet/ItemViewModel.cs b/Wallet/ItemViewModel.cs index 3b77fe7..4e2fcb9 100644 --- a/Wallet/ItemViewModel.cs +++ b/Wallet/ItemViewModel.cs @@ -108,6 +108,7 @@ public partial class ItemViewModel : Publisher.Publish(Notify.As(Factory.Create(new List { Factory.Create(), + Factory.Create(), }))); } else diff --git a/Wallet/UpdateItemHander.cs b/Wallet/UpdateItemHander.cs index 0f0ac7b..8b680c3 100644 --- a/Wallet/UpdateItemHander.cs +++ b/Wallet/UpdateItemHander.cs @@ -12,7 +12,7 @@ public class UpdateItemHander(IDbContextFactory dbContextFactory) public async Task Handle(UpdateEventArgs> args, CancellationToken cancellationToken) { - if (args.Value is Item<(Guid, string, ItemConfiguration)> item) + if (args.Sender is Item<(Guid, string, ItemConfiguration)> item) { (Guid id, string name, ItemConfiguration configuration) = item.Value; diff --git a/Wallet/UpdateItemStateHandler.cs b/Wallet/UpdateItemStateHandler.cs index 9ef4641..c5dd8af 100644 --- a/Wallet/UpdateItemStateHandler.cs +++ b/Wallet/UpdateItemStateHandler.cs @@ -10,7 +10,7 @@ public class UpdateItemStateHandler(IDbContextFactory dbContextFa public async Task Handle(UpdateEventArgs<(Guid, int)> args, CancellationToken cancellationToken) { - if (args.Value is (Guid id, int state)) + if (args.Sender is (Guid id, int state)) { using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken); if (await context.FindAsync(id) is ItemEntry result)