WIP: Item counts
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Main" Route="Wallet">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
</NavigateAction>
|
||||
</ConditionAction>
|
||||
<ConditionAction>
|
||||
@@ -25,7 +25,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Left" Route="ItemCollection">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
<Parameter Key="Transition" Value="FromRight" />
|
||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||
@@ -33,4 +33,7 @@
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
<NavigationViewItem.InfoBadge>
|
||||
<InfoBadge Value="{Binding Key}" />
|
||||
</NavigationViewItem.InfoBadge>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -108,6 +108,7 @@ public partial class App : Application
|
||||
services.AddHandler<CreateItemHandler>();
|
||||
services.AddHandler<UpdateItemHander>();
|
||||
services.AddHandler<UpdateItemStateHandler>();
|
||||
services.AddHandler<CountCategoriesHandler>();
|
||||
|
||||
services.AddHandler<OpenWalletHandler>();
|
||||
|
||||
@@ -184,6 +185,8 @@ public partial class App : Application
|
||||
|
||||
services.AddHandler<HyperlinkHandler>();
|
||||
|
||||
services.AddHandler<ItemChangedHandler>(ServiceLifetime.Singleton);
|
||||
|
||||
services.AddHandler<ArchiveItemHandler>();
|
||||
services.AddHandler<UnarchiveItemHandler>();
|
||||
services.AddHandler<FavouriteItemHandler>();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Main" Route="Wallet">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
</NavigateAction>
|
||||
</ConditionAction>
|
||||
<ConditionAction>
|
||||
@@ -25,7 +25,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Left" Route="ItemCollection">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
<Parameter Key="Transition" Value="FromRight" />
|
||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||
@@ -33,4 +33,7 @@
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
<NavigationViewItem.InfoBadge>
|
||||
<InfoBadge Value="{Binding Key}" />
|
||||
</NavigationViewItem.InfoBadge>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:Wallet"
|
||||
x:DataType="vm:CategoryNavigationViewModel"
|
||||
Content="{Binding Filter}"
|
||||
Content="{Binding Value}"
|
||||
IsSelected="{Binding Selected}">
|
||||
<Interaction.Behaviors>
|
||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
||||
@@ -15,7 +15,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Main" Route="Wallet">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
</NavigateAction>
|
||||
</ConditionAction>
|
||||
<ConditionAction>
|
||||
@@ -25,7 +25,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Left" Route="ItemCollection">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
<Parameter Key="Transition" Value="FromRight" />
|
||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Main" Route="Wallet">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
</NavigateAction>
|
||||
</ConditionAction>
|
||||
<ConditionAction>
|
||||
@@ -25,7 +25,7 @@
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Region="Left" Route="ItemCollection">
|
||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
||||
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||
<Parameter Key="Transition" Value="FromRight" />
|
||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||
@@ -33,5 +33,8 @@
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
<NavigationViewItem.InfoBadge>
|
||||
<InfoBadge Value="{Binding Key}" />
|
||||
</NavigationViewItem.InfoBadge>
|
||||
</NavigationViewItem>
|
||||
|
||||
|
||||
@@ -2,10 +2,20 @@
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
[Notification(typeof(NotifyEventArgs<Item<int>>), "All")]
|
||||
public partial class AllNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string filter) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
||||
IServiceFactory factory, IMediator mediator,
|
||||
IPublisher publisher, ISubscription subscriber, IDisposer disposer, int key, string value) :
|
||||
FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
INotificationHandler<NotifyEventArgs<Item<int>>>
|
||||
{
|
||||
public Task Handle(NotifyEventArgs<Item<int>> args)
|
||||
{
|
||||
if (args.Sender is Item<int> item)
|
||||
{
|
||||
Key = item.Value;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Wallet;
|
||||
|
||||
public record ArchiveEventArgs<TValue>(TValue Value);
|
||||
public record ArchiveEventArgs<TSender>(TSender Sender);
|
||||
@@ -4,7 +4,8 @@ namespace Wallet;
|
||||
|
||||
public class ArchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IMediator mediator) :
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ArchiveEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(ArchiveEventArgs<Item> args)
|
||||
@@ -21,6 +22,7 @@ public class ArchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decorato
|
||||
bool>(new UpdateEventArgs<(Guid, int)>((id, 2)));
|
||||
|
||||
cache.Remove(item);
|
||||
publisher.Publish(Changed.As(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,24 @@
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
[Notification(typeof(NotifyEventArgs<Item<int>>), "Archive")]
|
||||
public partial class ArchiveNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string name) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
int key,
|
||||
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
INotificationHandler<NotifyEventArgs<Item<int>>>
|
||||
{
|
||||
public Task Handle(NotifyEventArgs<Item<int>> args)
|
||||
{
|
||||
if (args.Sender is Item<int> item)
|
||||
{
|
||||
Key = item.Value;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,5 @@ public partial class CategoriesNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string name) : FilterNavigationViewModel<CategoryNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer, name)
|
||||
{
|
||||
|
||||
}
|
||||
int key,
|
||||
string value) : FilterNavigationViewModel<CategoryNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer, key, value);
|
||||
@@ -8,4 +8,4 @@ public partial class CategoryNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string filter) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
||||
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, 0, value);
|
||||
@@ -13,15 +13,19 @@ public class ConfirmCreateItemHandler(IMediator mediator,
|
||||
if (itemHeaderConfiguration.Service is ItemHeaderConfiguration headerConfiguration &&
|
||||
itemConfigurationDecorator.Service is ItemConfiguration itemConfiguration)
|
||||
{
|
||||
string? name = headerConfiguration?.Name;
|
||||
if (name is not null)
|
||||
if (headerConfiguration.Name is { Length: > 0 } name &&
|
||||
headerConfiguration.Category is { Length: > 0 } category)
|
||||
{
|
||||
Guid id = Guid.NewGuid();
|
||||
publisher.Publish(Created.As(new Item<(Guid, string)>((id, name))));
|
||||
|
||||
Item<(Guid, string)> item = new((id, name));
|
||||
publisher.Publish(Created.As(item));
|
||||
|
||||
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string,
|
||||
ItemConfiguration)>((id, name, "", itemConfiguration)));
|
||||
ItemConfiguration)>((id, name, category, itemConfiguration)));
|
||||
|
||||
publisher.Publish(Changed.As(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public class ConfirmUpdateItemHandler(IDecoratorService<Item<(Guid, string)>> it
|
||||
|
||||
await mediator.Handle<UpdateEventArgs<Item<(Guid, string, ItemConfiguration)>>, bool>(new UpdateEventArgs<Item<(Guid, string,
|
||||
ItemConfiguration)>>(new Item<(Guid, string, ItemConfiguration)>((id, name, itemConfiguration))));
|
||||
|
||||
publisher.Publish(Changed.As(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using Toolkit.Foundation;
|
||||
using Wallet.Data;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class CountCategoriesHandler(IDbContextFactory<WalletContext> dbContextFactory) :
|
||||
IHandler<CountEventArgs<ItemCategory>, IReadOnlyCollection<(string, int)>>
|
||||
{
|
||||
public async Task<IReadOnlyCollection<(string, int)>> Handle(CountEventArgs<ItemCategory> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var stateCounts = await context.Items
|
||||
.GroupBy(i => i.State)
|
||||
.Select(g => new
|
||||
{
|
||||
g.Key,
|
||||
Count = g.Count()
|
||||
})
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
|
||||
var categoryCounts = await context.Items.Where(x => !string.IsNullOrEmpty(x.Category))
|
||||
.GroupBy(i => i.Category)
|
||||
.Select(g => new
|
||||
{
|
||||
g.Key,
|
||||
Count = g.Count()
|
||||
})
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
|
||||
int allCount = stateCounts.Where(x => x.Key != 2).Sum(x => x.Count);
|
||||
int favouritesCount = stateCounts.Where(x => x.Key == 1).Sum(x => x.Count);
|
||||
int archiveCount = stateCounts.Where(x => x.Key == 2).Sum(x => x.Count);
|
||||
|
||||
List<(string, int)> combinedCounts =
|
||||
[
|
||||
new("Favourites", favouritesCount),
|
||||
new("Archive", archiveCount),
|
||||
new("All", allCount)
|
||||
];
|
||||
|
||||
foreach ((string key, int count) in categoryCounts.Select(x => (x.Key, x.Count)))
|
||||
{
|
||||
combinedCounts.Add((key, count));
|
||||
}
|
||||
|
||||
return combinedCounts;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Wallet;
|
||||
|
||||
public record FavouriteEventArgs<TValue>(TValue Value);
|
||||
public record FavouriteEventArgs<TSender>(TSender Sender);
|
||||
@@ -3,7 +3,8 @@
|
||||
namespace Wallet;
|
||||
|
||||
public class FavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||
IMediator mediator) :
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<FavouriteEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(FavouriteEventArgs<Item> args)
|
||||
@@ -14,6 +15,8 @@ public class FavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decora
|
||||
{
|
||||
(Guid id, string name) = item.Value;
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 1)));
|
||||
|
||||
publisher.Publish(Changed.As(item));
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
|
||||
namespace Wallet;
|
||||
|
||||
public partial class FilterNavigationViewModel :
|
||||
ObservableCollection<IWalletNavigationViewModel>,
|
||||
ObservableCollection<IWalletNavigationViewModel, int, string>,
|
||||
IWalletNavigationViewModel,
|
||||
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
||||
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
||||
@@ -12,9 +12,6 @@ public partial class FilterNavigationViewModel :
|
||||
[ObservableProperty]
|
||||
private bool activated;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? filter;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
@@ -24,9 +21,10 @@ public partial class FilterNavigationViewModel :
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
int key,
|
||||
string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
||||
{
|
||||
Filter = filter;
|
||||
|
||||
}
|
||||
|
||||
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
||||
@@ -37,7 +35,7 @@ public partial class FilterNavigationViewModel :
|
||||
}
|
||||
|
||||
public partial class FilterNavigationViewModel<TWalletNavigation> :
|
||||
ObservableCollection<TWalletNavigation>,
|
||||
ObservableCollection<TWalletNavigation, int, string>,
|
||||
IWalletNavigationViewModel,
|
||||
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
||||
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
||||
@@ -47,9 +45,6 @@ public partial class FilterNavigationViewModel<TWalletNavigation> :
|
||||
[ObservableProperty]
|
||||
private bool activated;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? filter;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
@@ -59,9 +54,10 @@ public partial class FilterNavigationViewModel<TWalletNavigation> :
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
int key,
|
||||
string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
||||
{
|
||||
Filter = filter;
|
||||
|
||||
}
|
||||
|
||||
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class ItemChangedHandler(IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ChangedEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public async Task Handle(ChangedEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
IReadOnlyCollection<(string, int)>? categoryCounts = await mediator.Handle<CountEventArgs<ItemCategory>,
|
||||
IReadOnlyCollection<(string, int)>>(Count.As<ItemCategory>());
|
||||
|
||||
if (categoryCounts is { Count: > 0 } )
|
||||
{
|
||||
foreach ((string key, int count) in categoryCounts)
|
||||
{
|
||||
publisher.Publish(Notify.As(new Item<int>(count)), key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,6 @@
|
||||
public class ItemHeaderConfiguration
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
public string? Category { get; set; }
|
||||
}
|
||||
@@ -70,6 +70,7 @@ public partial class ItemHeaderViewModel :
|
||||
if (args.Sender is ItemCategory<string> category)
|
||||
{
|
||||
Category = category.Value;
|
||||
configuration.Category = category.Value;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class QueryWalletHandler(IDbContextFactory<WalletContext> dbContextFactor
|
||||
Handle(QueryEventArgs<Wallet<(string, string)>> args,CancellationToken cancellationToken)
|
||||
{
|
||||
List<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)> items = [];
|
||||
if (args.Value is Wallet<(string, string)> Wallet)
|
||||
if (args.Sender is Wallet<(string, string)> Wallet)
|
||||
{
|
||||
(string filter, string text) = Wallet.Sender;
|
||||
|
||||
|
||||
@@ -2,10 +2,24 @@
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
[Notification(typeof(NotifyEventArgs<Item<int>>), "Favourites")]
|
||||
public partial class StarredNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string name) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
int key,
|
||||
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
INotificationHandler<NotifyEventArgs<Item<int>>>
|
||||
{
|
||||
public Task Handle(NotifyEventArgs<Item<int>> args)
|
||||
{
|
||||
if (args.Sender is Item<int> item)
|
||||
{
|
||||
Key = item.Value;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Wallet;
|
||||
|
||||
public record UnarchiveEventArgs<TValue>(TValue Value);
|
||||
public record UnarchiveEventArgs<TSender>(TSender Sender);
|
||||
@@ -1,12 +1,11 @@
|
||||
using Wallet.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||
IDbContextFactory<WalletContext> dbContextFactory) :
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<UnarchiveEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(UnarchiveEventArgs<Item> args)
|
||||
@@ -17,12 +16,11 @@ public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decora
|
||||
{
|
||||
(Guid id, string name) = item.Value;
|
||||
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync();
|
||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
||||
{
|
||||
result.State = 0;
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>,
|
||||
bool>(new UpdateEventArgs<(Guid, int)>((id, 0)));
|
||||
|
||||
cache.Add(item);
|
||||
publisher.Publish(Changed.As(item));
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Wallet;
|
||||
|
||||
public record UnfavouriteEventArgs<TValue>(TValue Value);
|
||||
public record UnfavouriteEventArgs<TSender>(TSender Sender);
|
||||
@@ -1,8 +1,10 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class UnfavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||
IMediator mediator) :
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<UnfavouriteEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(UnfavouriteEventArgs<Item> args)
|
||||
@@ -13,6 +15,8 @@ public class UnfavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> deco
|
||||
{
|
||||
(Guid id, string name) = item.Value;
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 0)));
|
||||
|
||||
publisher.Publish(Changed.As(item));
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -12,15 +12,12 @@ public class UpdateItemStateHandler(IDbContextFactory<WalletContext> dbContextFa
|
||||
{
|
||||
if (args.Value is (Guid id, int state))
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
||||
{
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
||||
{
|
||||
result.State = state;
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}, cancellationToken);
|
||||
result.State = state;
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -46,10 +46,10 @@ public partial class WalletNavigationViewModel :
|
||||
|
||||
public Task Handle(OpenedEventArgs<Wallet> args)
|
||||
{
|
||||
Add<AllNavigationViewModel>("All");
|
||||
Add<StarredNavigationViewModel>("Starred");
|
||||
Add<ArchiveNavigationViewModel>("Archive");
|
||||
Add<CategoriesNavigationViewModel>("Categories");
|
||||
Add<AllNavigationViewModel>("All", 0);
|
||||
Add<StarredNavigationViewModel>("Starred", 0);
|
||||
Add<ArchiveNavigationViewModel>("Archive", 0);
|
||||
Add<CategoriesNavigationViewModel>("Categories", 0);
|
||||
|
||||
Opened = true;
|
||||
return Task.CompletedTask;
|
||||
|
||||
Reference in New Issue
Block a user