Fixed dyanmically adding/removing items without the need to reload the whole bar
This commit is contained in:
@@ -6,30 +6,30 @@ public class ConfigurationChangedHandler(IMediator mediator,
|
||||
IViewModelCache<Guid, IWidgetComponentViewModel> cache) :
|
||||
INotificationHandler<ConfigurationChanged<PrimaryWidgetConfiguration>>
|
||||
{
|
||||
public async ValueTask Handle(ConfigurationChanged<PrimaryWidgetConfiguration> notification,
|
||||
public async ValueTask Handle(ConfigurationChanged<PrimaryWidgetConfiguration> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (KeyValuePair<Guid, IWidgetComponentViewModel> cached in cache)
|
||||
foreach (KeyValuePair<Guid, IWidgetComponentViewModel> item in cache)
|
||||
{
|
||||
if (configuration.FirstOrDefault(x => x.Id == cached.Key) == null)
|
||||
if (configuration.FirstOrDefault(x => x.Id == item.Key) == null)
|
||||
{
|
||||
await mediator.PublishAsync(new Removed<IWidgetComponentViewModel>(cached.Value),
|
||||
await mediator.PublishAsync(new Removed<IWidgetComponentViewModel>(item.Value),
|
||||
cancellationToken);
|
||||
|
||||
cache.Remove(cached.Key);
|
||||
cache.Remove(item.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (PrimaryCommandConfiguration item in configuration)
|
||||
{
|
||||
|
||||
//if (!cache.ContainsKey(item.Id))
|
||||
//{
|
||||
// factory.CreateAsync(item);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
|
||||
//}
|
||||
} }
|
||||
if (!cache.ContainsKey(item.Id))
|
||||
{
|
||||
if (factory.Create(item) is IWidgetComponentViewModel value)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<IWidgetComponentViewModel>(value),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user