Add suport for adding new items which are sorted without reloading the entrie list
This commit is contained in:
@@ -9,6 +9,8 @@ using Toolkit.Foundation;
|
|||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using HotAvalonia;
|
using HotAvalonia;
|
||||||
using Bitvault.Data;
|
using Bitvault.Data;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Bitvault.Avalonia;
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
@@ -41,6 +43,9 @@ public partial class App : Application
|
|||||||
{
|
{
|
||||||
args.AddServices(services =>
|
args.AddServices(services =>
|
||||||
{
|
{
|
||||||
|
services.AddTransient<IComparer<Item>>(provider => Comparer<Item>.Create((x, z) => x.Name!.CompareTo(z.Name)));
|
||||||
|
services.AddCache<Item>();
|
||||||
|
|
||||||
services.AddTransient<IKeyGenerator, KeyGenerator>();
|
services.AddTransient<IKeyGenerator, KeyGenerator>();
|
||||||
services.AddTransient<IEncryptor, AesEncryptor>();
|
services.AddTransient<IEncryptor, AesEncryptor>();
|
||||||
services.AddTransient<IDecryptor, AesDecryptor>();
|
services.AddTransient<IDecryptor, AesDecryptor>();
|
||||||
@@ -89,7 +94,7 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
||||||
|
|
||||||
services.AddHandler<CreateItemHandler>();
|
services.AddHandler<CreateItemHandler>(ServiceLifetime.Singleton);
|
||||||
services.AddHandler<ItemActivatedHandler>();
|
services.AddHandler<ItemActivatedHandler>();
|
||||||
});
|
});
|
||||||
})!);
|
})!);
|
||||||
|
|||||||
@@ -3,6 +3,4 @@
|
|||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ContainerComponent(IComponentBuilder builder) : Component(builder),
|
public class ContainerComponent(IComponentBuilder builder) : Component(builder),
|
||||||
IContainerComponent
|
IContainerComponent;
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,7 @@ namespace Bitvault;
|
|||||||
|
|
||||||
public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbContextFactory,
|
public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbContextFactory,
|
||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider,
|
||||||
|
ICache<Item> cache,
|
||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,8 @@ public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbC
|
|||||||
{
|
{
|
||||||
if (args.Options is ContainerViewModelConfiguration configuration)
|
if (args.Options is ContainerViewModelConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
cache.Clear();
|
||||||
|
|
||||||
ExpressionStarter<ItemEntry> predicate = PredicateBuilder.New<ItemEntry>(true);
|
ExpressionStarter<ItemEntry> predicate = PredicateBuilder.New<ItemEntry>(true);
|
||||||
|
|
||||||
if (configuration.Filter == "All")
|
if (configuration.Filter == "All")
|
||||||
@@ -40,7 +43,7 @@ public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbC
|
|||||||
{
|
{
|
||||||
x.Id,
|
x.Id,
|
||||||
x.Name
|
x.Name
|
||||||
}).ToListAsync();
|
}).OrderBy(x => x.Name).ToListAsync();
|
||||||
|
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
|
|
||||||
@@ -51,8 +54,8 @@ public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbC
|
|||||||
|
|
||||||
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1) is ItemNavigationViewModel viewModel)
|
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1) is ItemNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
await publisher.Publish(new CreateEventArgs<ItemNavigationViewModel>(viewModel),
|
cache.Add(new Item { Id = item.Id, Name = item.Name });
|
||||||
nameof(ContainerViewModel), cancellationToken);
|
await publisher.Publish(Create.As(viewModel), nameof(ContainerViewModel), cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
using Bitvault.Data;
|
using Bitvault.Data;
|
||||||
|
using HarfBuzzSharp;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory, IPublisher publisher) :
|
public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory,
|
||||||
|
IPublisher publisher) :
|
||||||
IHandler<CreateEventArgs<ItemConfiguration>, bool>
|
IHandler<CreateEventArgs<ItemConfiguration>, bool>
|
||||||
{
|
{
|
||||||
public async Task<bool> Handle(CreateEventArgs<ItemConfiguration> args,
|
public async Task<bool> Handle(CreateEventArgs<ItemConfiguration> args,
|
||||||
@@ -27,7 +29,9 @@ public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFa
|
|||||||
|
|
||||||
if (result is not null)
|
if (result is not null)
|
||||||
{
|
{
|
||||||
await publisher.Publish(Activated.As(new Item { Id = result.Entity.Id }), cancellationToken);
|
Item item = new() { Id = result.Entity.Id, Name = configuration.Name };
|
||||||
|
await publisher.Publish(Activated.As(item), cancellationToken);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,8 @@
|
|||||||
public record Item
|
public record Item
|
||||||
{
|
{
|
||||||
public int Id { get; init; }
|
public int Id { get; init; }
|
||||||
|
|
||||||
|
public string? Name { get; init; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,29 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using FluentAvalonia.Core;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ItemActivatedHandler(IServiceProvider serviceProvider,
|
public class ItemActivatedHandler(IServiceProvider serviceProvider,
|
||||||
IProxyService<IPublisher> proxyPublisher) :
|
ICache<Item> cache,
|
||||||
|
IPublisher publisher) :
|
||||||
INotificationHandler<ActivatedEventArgs<Item>>
|
INotificationHandler<ActivatedEventArgs<Item>>
|
||||||
{
|
{
|
||||||
public async Task Handle(ActivatedEventArgs<Item> args,
|
public async Task Handle(ActivatedEventArgs<Item> args,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (args.Value is Item item)
|
||||||
{
|
{
|
||||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||||
|
|
||||||
if (serviceFactory.Create<ItemNavigationViewModel>(2, "efesf", "Description " + 1) is ItemNavigationViewModel viewModel)
|
cache.Add(item);
|
||||||
|
int index = cache.IndexOf(item);
|
||||||
|
|
||||||
|
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1) is ItemNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
// somehow, we need to get back out of the scope back to the compoment level, this currently doesnt work, and we need a better and cleaner way
|
await publisher.Publish(Insert.As(index, viewModel), nameof(ContainerViewModel), cancellationToken);
|
||||||
await proxyPublisher.Proxy.Publish(new CreateEventArgs<ItemNavigationViewModel>(viewModel),
|
}
|
||||||
nameof(ContainerViewModel), cancellationToken);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user