Show initial category count
This commit is contained in:
@@ -5,14 +5,10 @@ namespace Wallet.Avalonia.Desktop;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
[STAThread]
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
|
||||
@@ -33,4 +33,7 @@
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
<NavigationViewItem.InfoBadge>
|
||||
<InfoBadge Value="{Binding Key}" />
|
||||
</NavigationViewItem.InfoBadge>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<Button MinWidth="132" Content="Create Wallet">
|
||||
<Interaction.Behaviors>
|
||||
<EventTriggerBehavior EventName="Click">
|
||||
<NavigateAction Region="self" Route="CreateWallet" />
|
||||
<NavigateAction Region="{x:Type ContentDialog}" Route="CreateWallet" />
|
||||
</EventTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</Button>
|
||||
|
||||
@@ -8,4 +8,5 @@ public partial class CategoryNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, 0, value);
|
||||
int key,
|
||||
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, key, value);
|
||||
@@ -8,12 +8,12 @@ public class ItemChangedHandler(IMediator mediator,
|
||||
{
|
||||
public async Task Handle(ChangedEventArgs<Item> args)
|
||||
{
|
||||
IReadOnlyCollection<(string, int)>? categoryCounts = await mediator.Handle<CountEventArgs<Item>,
|
||||
IReadOnlyCollection<(string, int)>? counts = await mediator.Handle<CountEventArgs<Item>,
|
||||
IReadOnlyCollection<(string, int)>>(Count.As<Item>());
|
||||
|
||||
if (categoryCounts is { Count: > 0 } )
|
||||
if (counts is { Count: > 0 } )
|
||||
{
|
||||
foreach ((string key, int count) in categoryCounts)
|
||||
foreach ((string key, int count) in counts)
|
||||
{
|
||||
publisher.Publish(Notify.As(new Item<int>(count)), key);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public partial class ItemCollectionViewModel :
|
||||
ObservableCollection<ItemNavigationViewModel>,
|
||||
INotificationHandler<NotifyEventArgs<Filter>>,
|
||||
INotificationHandler<NotifyEventArgs<Search<string>>>,
|
||||
INavigationBackStack
|
||||
IKeepAlive
|
||||
{
|
||||
[ObservableProperty]
|
||||
public string? named;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class QueryWalletHandler(IDbContextFactory<WalletContext> dbContextFactor
|
||||
{
|
||||
predicate = predicate.And(x => x.State != 2);
|
||||
}
|
||||
else if (filter == "Starred")
|
||||
else if (filter == "Favourites")
|
||||
{
|
||||
predicate = predicate.And(x => x.State != 2 && x.State == 1);
|
||||
}
|
||||
|
||||
@@ -2,23 +2,27 @@
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class SynchronizeCategoriesNavigationViewModelHandler(IItemConfigurationCollection configurations,
|
||||
public class SynchronizeCategoriesNavigationViewModelHandler(IMediator mediator,
|
||||
IItemConfigurationCollection configurations,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<SynchronizeEventArgs<CategoryNavigationViewModel>>
|
||||
{
|
||||
public Task Handle(SynchronizeEventArgs<CategoryNavigationViewModel> args)
|
||||
public async Task Handle(SynchronizeEventArgs<CategoryNavigationViewModel> args)
|
||||
{
|
||||
IReadOnlyCollection<(string Name, int Count)>? counts = await mediator.Handle<CountEventArgs<Item>,
|
||||
IReadOnlyCollection<(string, int)>>(Count.As<Item>());
|
||||
|
||||
foreach (KeyValuePair<string, Func<ItemConfiguration>> configuration in configurations)
|
||||
{
|
||||
if (serviceFactory.Create<CategoryNavigationViewModel>(args => args.Initialize(),
|
||||
configuration.Key)
|
||||
int count = counts?.FirstOrDefault(x => x.Name == configuration.Key).Count ?? 0;
|
||||
string name = configuration.Key;
|
||||
|
||||
if (serviceFactory.Create<CategoryNavigationViewModel>(args => args.Initialize(), count, name)
|
||||
is CategoryNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Create.As(viewModel), nameof(CategoriesNavigationViewModel));
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ public class SynchronizeItemCollectionViewModelHandler(IMediator mediator,
|
||||
|
||||
IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite, bool Archived)>? results =
|
||||
await mediator.Handle<QueryEventArgs<Wallet<(string?, string?)>>,
|
||||
IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite, bool Archived)>>(Query.As(new Wallet<(string?, string?)>((configuration.Filter, configuration.Query))));
|
||||
IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite,
|
||||
bool Archived)>>(Query.As(new Wallet<(string?, string?)>((configuration.Filter, configuration.Query))));
|
||||
|
||||
if (results is not null)
|
||||
{
|
||||
@@ -27,7 +28,8 @@ public class SynchronizeItemCollectionViewModelHandler(IMediator mediator,
|
||||
{
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
IDecoratorService<Item<(Guid, string)>> decoratorService = serviceScope.ServiceProvider.GetRequiredService<IDecoratorService<Item<(Guid, string)>>>();
|
||||
IDecoratorService<Item<(Guid, string)>> decoratorService = serviceScope.ServiceProvider
|
||||
.GetRequiredService<IDecoratorService<Item<(Guid, string)>>>();
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(args => args.Initialize(),
|
||||
Id, Name, "Description", Category, selected, Favourite, Archived)
|
||||
|
||||
@@ -16,8 +16,8 @@ public class SynchronizeItemContentViewModelHandler(IDecoratorService<Item<(Guid
|
||||
{
|
||||
if (item.Value is (Guid Id, _))
|
||||
{
|
||||
(_, _, _, _, ItemConfiguration? configuration) = await mediator.Handle<RequestEventArgs<Item<Guid>>, (Guid, string, string?, string,
|
||||
ItemConfiguration?)>(Request.As(new Item<Guid>(Id)));
|
||||
(_, _, _, _, ItemConfiguration? configuration) = await mediator.Handle<RequestEventArgs<Item<Guid>>,
|
||||
(Guid, string, string?, string, ItemConfiguration?)>(Request.As(new Item<Guid>(Id)));
|
||||
|
||||
if (configuration is not null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user