diff --git a/Bitvault.Avalonia/App.axaml.cs b/Bitvault.Avalonia/App.axaml.cs index 4441d7d..671408c 100644 --- a/Bitvault.Avalonia/App.axaml.cs +++ b/Bitvault.Avalonia/App.axaml.cs @@ -54,10 +54,10 @@ public partial class App : Application { args.AddServices(services => { - services.AddTransient>(provider => Comparer.Create((x, z) => - StringComparer.CurrentCultureIgnoreCase.Compare(x.Name, z.Name))); + services.AddTransient>>(provider => Comparer>.Create((x, z) => + StringComparer.CurrentCultureIgnoreCase.Compare(x.Value.Item2, z.Value.Item2))); - services.AddCache(); + services.AddCache>(); services.AddTransient(_ => provider.GetRequiredService>>()); @@ -133,7 +133,7 @@ public partial class App : Application services.AddTemplate(); services.AddTemplate(); - services.AddScoped, ValueStore>(); + services.AddScoped>, ValueStore>>(); services.AddHandler(); services.AddHandler(); diff --git a/Bitvault.Avalonia/CreateItemActionView.axaml b/Bitvault.Avalonia/CreateItemActionView.axaml index 0ed4660..ab517e2 100644 --- a/Bitvault.Avalonia/CreateItemActionView.axaml +++ b/Bitvault.Avalonia/CreateItemActionView.axaml @@ -32,6 +32,12 @@ + + + diff --git a/Bitvault.Avalonia/ItemCategoryNavigationView.axaml b/Bitvault.Avalonia/ItemCategoryNavigationView.axaml index 581458f..289297b 100644 --- a/Bitvault.Avalonia/ItemCategoryNavigationView.axaml +++ b/Bitvault.Avalonia/ItemCategoryNavigationView.axaml @@ -4,31 +4,14 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="using:Bitvault" x:DataType="vm:ItemCategoryNavigationViewModel" - Content="{Binding Name}" IsSelected="{Binding Selected, Mode=TwoWay}"> - - - - - - - - - - - - - - - - - - - + + + + + + diff --git a/Bitvault.Avalonia/LockerNavigationView.axaml b/Bitvault.Avalonia/LockerNavigationView.axaml index fff7f17..ef80b85 100644 --- a/Bitvault.Avalonia/LockerNavigationView.axaml +++ b/Bitvault.Avalonia/LockerNavigationView.axaml @@ -61,4 +61,7 @@ + + + diff --git a/Bitvault/AggerateItemViewModelHandler.cs b/Bitvault/AggerateItemViewModelHandler.cs index b55c7ab..58d5687 100644 --- a/Bitvault/AggerateItemViewModelHandler.cs +++ b/Bitvault/AggerateItemViewModelHandler.cs @@ -2,13 +2,15 @@ namespace Bitvault; -public class AggerateItemViewModelHandler(IMediator mediator, +public class AggerateItemViewModelHandler(IValueStore> valueStore, + IMediator mediator, IServiceFactory serviceFactory, IPublisher publisher) : INotificationHandler> { public Task Handle(AggerateEventArgs args) { + var d = valueStore; //if (serviceFactory.Create(false) is ItemHeaderViewModel viewModel) //{ // publisher.Publish(Create.As(viewModel), nameof(ItemViewModel)); diff --git a/Bitvault/AggerateLockerItemViewModelHandler.cs b/Bitvault/AggerateLockerItemViewModelHandler.cs index 9f12269..5b550e3 100644 --- a/Bitvault/AggerateLockerItemViewModelHandler.cs +++ b/Bitvault/AggerateLockerItemViewModelHandler.cs @@ -5,7 +5,7 @@ namespace Bitvault; public class AggerateLockerItemViewModelHandler(IMediator mediator, IServiceProvider serviceProvider, - ICache cache, + ICache> cache, IPublisher publisher) : INotificationHandler> @@ -29,11 +29,12 @@ public class AggerateLockerItemViewModelHandler(IMediator mediator, { IServiceScope serviceScope = serviceProvider.CreateScope(); IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService(); - IValueStore valueStore = serviceScope.ServiceProvider.GetRequiredService>(); + IValueStore> valueStore = serviceScope.ServiceProvider.GetRequiredService>>(); if (serviceFactory.Create(Id, Name, "Description", selected, Favourite, Archived) is ItemNavigationViewModel viewModel) { - Item item = new() { Id = Id, Name = Name }; + Item<(Guid, string)> item = new((Id, Name)); + valueStore.Set(item); cache.Add(item); diff --git a/Bitvault/ArchiveItemHandler.cs b/Bitvault/ArchiveItemHandler.cs index dd887be..363e315 100644 --- a/Bitvault/ArchiveItemHandler.cs +++ b/Bitvault/ArchiveItemHandler.cs @@ -2,21 +2,23 @@ namespace Bitvault; -public class ArchiveItemHandler(IValueStore valueStore, - ICache cache, +public class ArchiveItemHandler(IValueStore> valueStore, + ICache> cache, IMediator mediator) : - INotificationHandler> + INotificationHandler>> { - public async Task Handle(ArchiveEventArgs args) + public async Task Handle(ArchiveEventArgs> args) { try { - if (valueStore.Value is Item item) + if (valueStore.Value is Item<(Guid, string)> item) { if (cache.Contains(item)) { + (Guid id, string name) = item.Value; + await mediator.Handle, - bool>(new UpdateEventArgs<(Guid, int)>((item.Id, 2))); + bool>(new UpdateEventArgs<(Guid, int)>((id, 2))); cache.Remove(item); } diff --git a/Bitvault/ConfirmItemHandler.cs b/Bitvault/ConfirmItemHandler.cs index 6ec368c..fc537d2 100644 --- a/Bitvault/ConfirmItemHandler.cs +++ b/Bitvault/ConfirmItemHandler.cs @@ -2,32 +2,33 @@ namespace Bitvault; -public class ConfirmItemHandler(IValueStore valueStore, +public class ConfirmItemHandler(IValueStore> valueStore, IMediator mediator, IPublisher publisher) : - INotificationHandler> + INotificationHandler>> { - public async Task Handle(ConfirmEventArgs args) + public async Task Handle(ConfirmEventArgs> args) { - ItemHeaderConfiguration? configuration = await mediator.Handle, + ItemHeaderConfiguration? configuration = await mediator.Handle>, ItemHeaderConfiguration>(args); if (configuration is not null) { publisher.Publish(Notify.As(configuration)); - if (valueStore?.Value is Item item) + if (valueStore?.Value is Item<(Guid, string)> item) { - Guid id = item.Id; + (Guid id, string _) = item.Value; + string? name = configuration.Name; - Item newItem = new() { Id = id, Name = name }; + Item<(Guid, string)> newItem = new((id, name)); publisher.Publish(Modified.As(item, newItem)); valueStore.Set(newItem); await mediator.Handle, bool>(new UpdateEventArgs<(Guid, - ItemConfiguration)>((item.Id, new ItemConfiguration { Name = name }))); + ItemConfiguration)>((id, new ItemConfiguration { Name = name }))); } else { @@ -39,7 +40,7 @@ public class ConfirmItemHandler(IValueStore valueStore, if (Success) { - publisher.Publish(Created.As(new Item { Id = id, Name = name })); + publisher.Publish(Created.As(new Item<(Guid, string)>((id, name)))); } } } diff --git a/Bitvault/CreatedItemHandler.cs b/Bitvault/CreatedItemHandler.cs index 2aec2d4..3f7e23b 100644 --- a/Bitvault/CreatedItemHandler.cs +++ b/Bitvault/CreatedItemHandler.cs @@ -4,19 +4,21 @@ using Toolkit.Foundation; namespace Bitvault; public class CreatedItemHandler(IServiceProvider serviceProvider, - ICache cache, + ICache> cache, IPublisher publisher) : - INotificationHandler> + INotificationHandler>> { - public Task Handle(CreatedEventArgs args) + public Task Handle(CreatedEventArgs> args) { - if (args.Value is Item item) + if (args.Value is Item<(Guid, string)> item) { + (Guid id, string name) = item.Value; + IServiceScope serviceScope = serviceProvider.CreateScope(); IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService(); - IValueStore valueStore = serviceScope.ServiceProvider.GetRequiredService>(); + IValueStore> valueStore = serviceScope.ServiceProvider.GetRequiredService>>(); - if (serviceFactory.Create(item.Id, item.Name, "Description", true) + if (serviceFactory.Create(id, name, "Description", true) is ItemNavigationViewModel viewModel) { cache.Add(item); diff --git a/Bitvault/FavouriteItemHandler.cs b/Bitvault/FavouriteItemHandler.cs index d53ac0e..7bcd6ba 100644 --- a/Bitvault/FavouriteItemHandler.cs +++ b/Bitvault/FavouriteItemHandler.cs @@ -2,18 +2,18 @@ namespace Bitvault; -public class FavouriteItemHandler(IValueStore valueStore, +public class FavouriteItemHandler(IValueStore> valueStore, IMediator mediator) : - INotificationHandler> + INotificationHandler>> { - public async Task Handle(FavouriteEventArgs args) + public async Task Handle(FavouriteEventArgs> args) { try { - if (valueStore.Value is Item item) + if (valueStore.Value is Item<(Guid, string)> item) { - await mediator.Handle, bool>(new UpdateEventArgs<(Guid, - int)>((item.Id, 1))); + (Guid id, string name) = item.Value; + await mediator.Handle, bool>(new UpdateEventArgs<(Guid, int)>((id, 1))); } } catch diff --git a/Bitvault/Item.cs b/Bitvault/Item.cs index 46225e6..aa919d6 100644 --- a/Bitvault/Item.cs +++ b/Bitvault/Item.cs @@ -1,8 +1,5 @@ namespace Bitvault; -public record Item -{ - public Guid Id { get; init; } +public record Item(TValue Value); - public string? Name { get; init; } = ""; -} \ No newline at end of file +public record Item; \ No newline at end of file diff --git a/Bitvault/ItemCategoryNavigationViewModel.cs b/Bitvault/ItemCategoryNavigationViewModel.cs index 5040f2d..6155efb 100644 --- a/Bitvault/ItemCategoryNavigationViewModel.cs +++ b/Bitvault/ItemCategoryNavigationViewModel.cs @@ -9,7 +9,6 @@ public partial class ItemCategoryNavigationViewModel(IServiceProvider provider, IPublisher publisher, ISubscription subscriber, IDisposer disposer, - NamedComponent named, string name, bool selected = false) : Observable(provider, factory, mediator, publisher, subscriber, disposer), @@ -19,9 +18,6 @@ public partial class ItemCategoryNavigationViewModel(IServiceProvider provider, [ObservableProperty] private string name = name; - [ObservableProperty] - private string named = $"{named}"; - [ObservableProperty] private bool selected = selected; diff --git a/Bitvault/ItemContentViewModel.cs b/Bitvault/ItemContentViewModel.cs index cef2395..716c01e 100644 --- a/Bitvault/ItemContentViewModel.cs +++ b/Bitvault/ItemContentViewModel.cs @@ -2,8 +2,10 @@ namespace Bitvault; +[Aggerate(nameof(ItemContentViewModel))] public partial class ItemContentViewModel : ObservableCollection, + IItemEntryViewModel { public ItemContentViewModel(IServiceProvider provider, @@ -15,11 +17,6 @@ public partial class ItemContentViewModel : bool immutable = true) : base(provider, factory, mediator, publisher, subscriber, disposer) { Template = template; - - if (!immutable) - { - Insert(); - } } public IContentTemplate Template { get; set; } diff --git a/Bitvault/ItemHeaderViewModel.cs b/Bitvault/ItemHeaderViewModel.cs index 4167c5b..53d8023 100644 --- a/Bitvault/ItemHeaderViewModel.cs +++ b/Bitvault/ItemHeaderViewModel.cs @@ -36,7 +36,7 @@ public partial class ItemHeaderViewModel : Observable, } public Task Handle(ConfirmEventArgs args, - CancellationToken cancellationToken) => Task.FromResult(new ItemHeaderConfiguration { Name = Value }); + CancellationToken cancellationToken) => Task.FromResult(new ItemHeaderConfiguration { Name = Value! }); public Task Handle(UpdateEventArgs args) => Task.FromResult(Immutable = false); diff --git a/Bitvault/ModifiedItemHandler.cs b/Bitvault/ModifiedItemHandler.cs index c99c558..9cfcb44 100644 --- a/Bitvault/ModifiedItemHandler.cs +++ b/Bitvault/ModifiedItemHandler.cs @@ -5,20 +5,20 @@ namespace Bitvault; public class ModifiedItemHandler(IServiceProvider serviceProvider, IPublisher publisher) : - INotificationHandler> + INotificationHandler>> { - public Task Handle(ModifiedEventArgs args) + public Task Handle(ModifiedEventArgs> args) { - Item oldItem = args.OldView; - Item newItem = args.NewValue; + Item<(Guid, string)> oldItem = args.OldView; + Item<(Guid, string)> newItem = args.NewValue; - ICache cache = serviceProvider.GetRequiredService>(); - if (cache.TryGetValue(oldItem, out Item? cachedItem)) + ICache> cache = serviceProvider.GetRequiredService>>(); + if (cache.TryGetValue(oldItem, out Item<(Guid, string)>? cachedItem)) { if (cachedItem is not null) { IServiceScope serviceScope = serviceProvider.CreateScope(); - IValueStore valueStore = serviceScope.ServiceProvider.GetRequiredService>(); + IValueStore> valueStore = serviceScope.ServiceProvider.GetRequiredService>>(); int oldIndex = cache.IndexOf(cachedItem); cache.Remove(cachedItem); diff --git a/Bitvault/UnarchiveItemHandler.cs b/Bitvault/UnarchiveItemHandler.cs index 2df55e7..d808cec 100644 --- a/Bitvault/UnarchiveItemHandler.cs +++ b/Bitvault/UnarchiveItemHandler.cs @@ -4,21 +4,22 @@ using Toolkit.Foundation; namespace Bitvault; -public class UnarchiveItemHandler(IValueStore valueStore, +public class UnarchiveItemHandler(IValueStore> valueStore, IDbContextFactory dbContextFactory) : - INotificationHandler> + INotificationHandler>> { - public async Task Handle(UnarchiveEventArgs args) + public async Task Handle(UnarchiveEventArgs> args) { try { - if (valueStore.Value is Item item) + if (valueStore.Value is Item<(Guid, string)> item) { + (Guid id, string name) = item.Value; await Task.Run(async () => { using LockerContext context = await dbContextFactory.CreateDbContextAsync(); - if (await context.FindAsync(item.Id) is ItemEntry result) + if (await context.FindAsync(id) is ItemEntry result) { result.State = 0; await context.SaveChangesAsync(); diff --git a/Bitvault/UnfavouriteItemHandler.cs b/Bitvault/UnfavouriteItemHandler.cs index 24c4e63..e8d3de6 100644 --- a/Bitvault/UnfavouriteItemHandler.cs +++ b/Bitvault/UnfavouriteItemHandler.cs @@ -1,18 +1,18 @@ using Toolkit.Foundation; namespace Bitvault; -public class UnfavouriteItemHandler(IValueStore valueStore, +public class UnfavouriteItemHandler(IValueStore> valueStore, IMediator mediator) : - INotificationHandler> + INotificationHandler>> { - public async Task Handle(UnfavouriteEventArgs args) + public async Task Handle(UnfavouriteEventArgs> args) { try { - if (valueStore.Value is Item item) + if (valueStore.Value is Item<(Guid, string)> item) { - await mediator.Handle, bool>(new UpdateEventArgs<(Guid, - int)>((item.Id, 0))); + (Guid id, string name) = item.Value; + await mediator.Handle, bool>(new UpdateEventArgs<(Guid, int)>((id, 0))); } } catch