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