using CommunityToolkit.Mvvm.ComponentModel; using Toolkit.Foundation; namespace Bitvault; [Notification(typeof(AggerateEventArgs), nameof(ItemCollectionViewModel))] [Notification(typeof(CreateEventArgs), nameof(ItemCollectionViewModel))] [Notification(typeof(InsertEventArgs), nameof(ItemCollectionViewModel))] [Notification(typeof(MoveToEventArgs), nameof(ItemCollectionViewModel))] [Notification(typeof(NotifyEventArgs>), nameof(ItemCollectionViewModel))] public partial class ItemCollectionViewModel : ObservableCollection, INotificationHandler>, INotificationHandler>>, IBackStack { [ObservableProperty] public string? named; private LockerViewModelConfiguration configuration; public ItemCollectionViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, ISubscription subscriber, IDisposer disposer, IContentTemplate template, NamedComponent named, LockerViewModelConfiguration configuration, string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer) { Template = template; Named = $"{named}"; this.configuration = configuration with { Filter = filter }; } public IContentTemplate Template { get; set; } public Task Handle(NotifyEventArgs args) { if (args.Value is Filter filter) { configuration = configuration with { Filter = filter.Value }; Fetch(true); } return Task.CompletedTask; } public Task Handle(NotifyEventArgs> args) { if (args.Value is Search search) { configuration = configuration with { Query = search.Value }; Fetch(true); } return Task.CompletedTask; } public override Task OnActivated() { Publisher.Publish(Notify.As(Factory.Create(new List { Factory.Create(), Factory.Create(), }))); return base.OnActivated(); } protected override AggregateExpression BuildAggregateExpression() => new(Aggregate.As(configuration)); }