fIxed issue with filtering

This commit is contained in:
TheXamlGuy
2024-05-26 14:11:42 +01:00
parent 52a682d5fb
commit 859d16c85c
8 changed files with 55 additions and 45 deletions
@@ -1,19 +1,19 @@
namespace Bitvault;
public record ContainerToken
public record Container
{
public ContainerToken(string name, string password)
public Container(string name, string password)
{
Name = name;
Password = password;
}
public ContainerToken(string password)
public Container(string password)
{
Password = password;
}
public ContainerToken()
public Container()
{
}
+8 -8
View File
@@ -6,10 +6,10 @@ namespace Bitvault;
public partial class ContainerNavigationViewModel :
ObservableCollection<IContainerNavigationViewModel>,
IMainNavigationViewModel,
INotificationHandler<OpenedEventArgs<ContainerToken>>,
INotificationHandler<ClosedEventArgs<ContainerToken>>,
INotificationHandler<ActivatedEventArgs<ContainerToken>>,
INotificationHandler<DeactivatedEventArgs<ContainerToken>>
INotificationHandler<OpenedEventArgs<Container>>,
INotificationHandler<ClosedEventArgs<Container>>,
INotificationHandler<ActivatedEventArgs<Container>>,
INotificationHandler<DeactivatedEventArgs<Container>>
{
[ObservableProperty]
private bool activated;
@@ -41,7 +41,7 @@ public partial class ContainerNavigationViewModel :
public IContentTemplate Template { get; set; }
public Task Handle(OpenedEventArgs<ContainerToken> args)
public Task Handle(OpenedEventArgs<Container> args)
{
Add<AllNavigationViewModel>("All");
Add<StarredNavigationViewModel>("Starred");
@@ -52,7 +52,7 @@ public partial class ContainerNavigationViewModel :
return Task.CompletedTask;
}
public Task Handle(ClosedEventArgs<ContainerToken> args)
public Task Handle(ClosedEventArgs<Container> args)
{
Opened = true;
Clear();
@@ -60,9 +60,9 @@ public partial class ContainerNavigationViewModel :
return Task.CompletedTask;
}
public Task Handle(DeactivatedEventArgs<ContainerToken> args) =>
public Task Handle(DeactivatedEventArgs<Container> args) =>
Task.FromResult(Activated = false);
public Task Handle(ActivatedEventArgs<ContainerToken> args) =>
public Task Handle(ActivatedEventArgs<Container> args) =>
Task.FromResult(Activated = true);
}
+30 -20
View File
@@ -4,34 +4,33 @@ using Toolkit.Foundation;
namespace Bitvault;
[Aggerate(nameof(ContainerViewModel))]
public partial class ContainerViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
IContentTemplate template,
NamedComponent named,
ContainerViewModelConfiguration configuration) : ObservableCollection<ItemNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
public partial class ContainerViewModel : ObservableCollection<ItemNavigationViewModel>,
INotificationHandler<NotifyEventArgs<Filter>>,
INotificationHandler<NotifyEventArgs<Search>>
{
[ObservableProperty]
private string named = $"{named}";
private string named;
public IContentTemplate Template { get; set; } = template;
public override async Task OnActivated()
public ContainerViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
IContentTemplate template,
ContainerViewModelConfiguration configuration,
NamedComponent named,
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
{
Publisher.Publish(Activated.As<ContainerToken>());
await base.OnActivated();
Template = template;
Named = $"{named}";
this.configuration = configuration with { Filter = filter };
}
public override async Task OnDeactivated()
{
Publisher.Publish(Deactivated.As<ContainerToken>());
await base.OnDeactivated();
}
private ContainerViewModelConfiguration configuration;
public IContentTemplate Template { get; set; }
public Task Handle(NotifyEventArgs<Filter> args)
{
@@ -55,6 +54,17 @@ public partial class ContainerViewModel(IServiceProvider provider,
return Task.CompletedTask;
}
public override async Task OnActivated()
{
Publisher.Publish(Activated.As<Container>());
await base.OnActivated();
}
public override async Task OnDeactivated()
{
Publisher.Publish(Deactivated.As<Container>());
await base.OnDeactivated();
}
protected override IAggerate OnPrepareAggregation(object? key) =>
Aggerate.With<ItemNavigationViewModel, ContainerViewModelConfiguration>(configuration) with { Key = key };
}
+3 -3
View File
@@ -7,12 +7,12 @@ namespace Bitvault;
public class CreateContainerHandler(IContainerFactory componentFactory,
IPublisher publisher) :
IHandler<CreateEventArgs<ContainerToken>, bool>
IHandler<CreateEventArgs<Container>, bool>
{
public async Task<bool> Handle(CreateEventArgs<ContainerToken> args,
public async Task<bool> Handle(CreateEventArgs<Container> args,
CancellationToken cancellationToken)
{
if (args.Value is ContainerToken container && container.Name is { Length: > 0 } name &&
if (args.Value is Container container && container.Name is { Length: > 0 } name &&
container.Password is { Length: > 0 } password)
{
if (componentFactory.Create(name) is IComponentHost host)
+1 -1
View File
@@ -22,5 +22,5 @@ public partial class CreateContainerViewModel(IServiceProvider provider,
private string password;
public async Task<bool> Confirm() =>
await Mediator.Handle<CreateEventArgs<ContainerToken>, bool>(Create.As(new ContainerToken(Name, Password)));
await Mediator.Handle<CreateEventArgs<Container>, bool>(Create.As(new Container(Name, Password)));
}
@@ -6,8 +6,8 @@ namespace Bitvault;
public partial class FilterContainerNavigationViewModel : Observable,
IContainerNavigationViewModel,
INotificationHandler<ActivatedEventArgs<ContainerToken>>,
INotificationHandler<DeactivatedEventArgs<ContainerToken>>
INotificationHandler<ActivatedEventArgs<Container>>,
INotificationHandler<DeactivatedEventArgs<Container>>
{
[ObservableProperty]
private bool activated;
@@ -29,10 +29,10 @@ public partial class FilterContainerNavigationViewModel : Observable,
Filter = filter;
}
public Task Handle(DeactivatedEventArgs<ContainerToken> args) =>
public Task Handle(DeactivatedEventArgs<Container> args) =>
Task.FromResult(Activated = false);
public Task Handle(ActivatedEventArgs<ContainerToken> args) =>
public Task Handle(ActivatedEventArgs<Container> args) =>
Task.FromResult(Activated = true);
[RelayCommand]
+3 -3
View File
@@ -6,12 +6,12 @@ namespace Bitvault;
public class OpenContainerHandler(ContainerConfiguration configuration,
ISecurityKeyFactory keyVaultFactory,
IContainerStorageFactory vaultStorage) :
IHandler<ActivateEventArgs<ContainerToken>, bool>
IHandler<ActivateEventArgs<Container>, bool>
{
public async Task<bool> Handle(ActivateEventArgs<ContainerToken> args,
public async Task<bool> Handle(ActivateEventArgs<Container> args,
CancellationToken cancellationToken)
{
if (args.Value is ContainerToken container && configuration.Name is { Length: > 0 } name && container.Password is { Length: > 0 } password)
if (args.Value is Container container && configuration.Name is { Length: > 0 } name && container.Password is { Length: > 0 } password)
{
if (configuration.Key?.Split(':') is { Length: >= 2 } keyPart)
{
+2 -2
View File
@@ -20,9 +20,9 @@ public partial class OpenContainerViewModel(IServiceProvider provider,
{
if (Password is { Length: > 0 })
{
if (await Mediator.Handle<ActivateEventArgs<ContainerToken>, bool>(Activate.As(new ContainerToken(Password))))
if (await Mediator.Handle<ActivateEventArgs<Container>, bool>(Activate.As(new Container(Password))))
{
Publisher.Publish(Opened.As<ContainerToken>());
Publisher.Publish(Opened.As<Container>());
}
}
}