Fixed dyanmically adding/removing items without the need to reload the whole bar

This commit is contained in:
TheXamlGuy
2024-01-13 11:40:40 +00:00
parent ff1d400531
commit 70e0ae9492
5 changed files with 55 additions and 38 deletions
@@ -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);
}
}
}
}
}