wip item images
This commit is contained in:
@@ -16,9 +16,10 @@ public class ConfirmCreateItemHandler(IMediator mediator,
|
||||
if (headerConfiguration.Name is { Length: > 0 } name &&
|
||||
headerConfiguration.Category is { Length: > 0 } category)
|
||||
{
|
||||
IImageDescriptor? imageDescriptor = headerConfiguration.ImageDescriptor;
|
||||
Guid id = Guid.NewGuid();
|
||||
|
||||
Item<(Guid, string)> item = new((id, name));
|
||||
Item<(Guid, string, string, IImageDescriptor?)> item = new((id, name, category, imageDescriptor));
|
||||
publisher.Publish(Created.As(item));
|
||||
|
||||
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class CreateItemViewModelHandler(IServiceFactory serviceFactory,
|
||||
IDecoratorService<ItemHeaderConfiguration> itemHeaderConfigurationDecorator) :
|
||||
IHandler<CreateEventArgs<ItemViewModel>, ItemViewModel?>
|
||||
{
|
||||
public Task<ItemViewModel?> Handle(CreateEventArgs<ItemViewModel> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
string? name = "";
|
||||
ItemState? state = null;
|
||||
|
||||
if (args.Parameters is { Length: 5 })
|
||||
{
|
||||
(name, bool _, bool _, bool _, state) = args.Parameters.CreateValueTuple<string, bool, bool, bool, ItemState>();
|
||||
}
|
||||
|
||||
if (args.Parameters is { Length: 2 })
|
||||
{
|
||||
(bool _, state) = args.Parameters.CreateValueTuple<bool, ItemState>();
|
||||
}
|
||||
|
||||
ItemHeaderConfiguration configuration = new()
|
||||
{
|
||||
Name = name
|
||||
};
|
||||
|
||||
itemHeaderConfigurationDecorator.Set(configuration);
|
||||
|
||||
if (serviceFactory.Create<ItemViewModel>(args => args.Initialize(), args.Parameters) is ItemViewModel itemViewModel)
|
||||
{
|
||||
itemViewModel.Add<ItemHeaderViewModel>(configuration, state, "", name);
|
||||
itemViewModel.Add<ItemContentViewModel>();
|
||||
|
||||
return Task.FromResult<ItemViewModel?>(itemViewModel);
|
||||
}
|
||||
|
||||
return Task.FromResult(default(ItemViewModel));
|
||||
}
|
||||
}
|
||||
@@ -6,26 +6,27 @@ namespace Wallet;
|
||||
public class ItemCreatedHandler(IServiceProvider serviceProvider,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<CreatedEventArgs<Item<(Guid, string)>>>
|
||||
INotificationHandler<CreatedEventArgs<Item<(Guid, string, string, IImageDescriptor?)>>>
|
||||
{
|
||||
public Task Handle(CreatedEventArgs<Item<(Guid, string)>> args)
|
||||
public Task Handle(CreatedEventArgs<Item<(Guid, string, string, IImageDescriptor?)>> args)
|
||||
{
|
||||
if (args.Sender is Item<(Guid, string)> item)
|
||||
if (args.Sender is Item<(Guid, string, string, IImageDescriptor?)> item)
|
||||
{
|
||||
(Guid id, string name) = item.Value;
|
||||
(Guid id, string name, string category, IImageDescriptor? imageDescriptor) = item.Value;
|
||||
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
IDecoratorService<Item<(Guid, string)>> decoratorService = serviceScope.ServiceProvider.GetRequiredService<IDecoratorService<Item<(Guid, string)>>>();
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(args => args.Initialize(),
|
||||
id, name, "Description", true)
|
||||
id, name, "Description", category, imageDescriptor, true)
|
||||
is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
cache.Add(item);
|
||||
Item<(Guid, string)> cachedItem = new((id, name));
|
||||
cache.Add(cachedItem);
|
||||
|
||||
int index = cache.IndexOf(item);
|
||||
decoratorService.Set(item);
|
||||
int index = cache.IndexOf(cachedItem);
|
||||
decoratorService.Set(cachedItem);
|
||||
|
||||
publisher.Publish(Insert.As(index, viewModel),
|
||||
nameof(ItemCollectionViewModel));
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
namespace Wallet;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
public class ItemHeaderConfiguration
|
||||
namespace Wallet;
|
||||
|
||||
public record ItemHeaderConfiguration
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
public string? Category { get; set; }
|
||||
|
||||
public IImageDescriptor? ImageDescriptor { get; set; }
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Toolkit.Foundation;
|
||||
namespace Wallet;
|
||||
|
||||
public partial class ItemHeaderViewModel :
|
||||
Observable<string, string>,
|
||||
Observable<string>,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>,
|
||||
@@ -19,6 +19,7 @@ public partial class ItemHeaderViewModel :
|
||||
|
||||
[ObservableProperty]
|
||||
private IImageDescriptor? imageDescriptor;
|
||||
|
||||
[ObservableProperty]
|
||||
private ItemState state;
|
||||
|
||||
@@ -30,13 +31,14 @@ public partial class ItemHeaderViewModel :
|
||||
IDisposer disposer,
|
||||
ItemHeaderConfiguration configuration,
|
||||
ItemState state,
|
||||
string key,
|
||||
string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
||||
string value,
|
||||
IImageDescriptor? imageDescriptor = null) : base(provider, factory, mediator, publisher, subscriber, disposer, value)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
|
||||
State = state;
|
||||
Value = value;
|
||||
ImageDescriptor = imageDescriptor;
|
||||
|
||||
Track(nameof(Value), () => Value, newValue => Value = newValue);
|
||||
}
|
||||
@@ -85,4 +87,12 @@ public partial class ItemHeaderViewModel :
|
||||
configuration.Name = Value;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnImageDescriptorChanging(IImageDescriptor? value)
|
||||
{
|
||||
if (configuration is not null)
|
||||
{
|
||||
configuration.ImageDescriptor = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
string name = "",
|
||||
string description = "",
|
||||
string category = "",
|
||||
IImageDescriptor? imageDescriptor = default,
|
||||
bool isSelected = false,
|
||||
bool favourite = false,
|
||||
bool archived = false) :
|
||||
@@ -44,6 +45,9 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
[ObservableProperty]
|
||||
private Guid id = id;
|
||||
|
||||
[ObservableProperty]
|
||||
private IImageDescriptor? imageDescriptor = imageDescriptor;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isSelected = isSelected;
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ public partial class ItemViewModel :
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
NamedComponent named,
|
||||
IDecoratorService<ItemHeaderConfiguration> itemHeaderConfigurationDecorator,
|
||||
string name = "",
|
||||
ImageDescriptor? imageDescriptor = null,
|
||||
bool fromCategory = false,
|
||||
bool favourite = false,
|
||||
bool archived = false,
|
||||
@@ -48,6 +50,16 @@ public partial class ItemViewModel :
|
||||
Favourite = favourite;
|
||||
Archived = archived;
|
||||
Name = name;
|
||||
|
||||
ItemHeaderConfiguration configuration = new()
|
||||
{
|
||||
Name = name
|
||||
};
|
||||
|
||||
itemHeaderConfigurationDecorator.Set(configuration);
|
||||
|
||||
Add<ItemHeaderViewModel>(configuration, state, name, imageDescriptor);
|
||||
Add<ItemContentViewModel>();
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user