Add ability to insert an ordered item at UI configuration time
This commit is contained in:
@@ -22,8 +22,8 @@ public class MediaControllerHandler(IMediator mediator,
|
||||
if (factory.Create(mediaController) is MediaControllerViewModel mediaControllerViewModel)
|
||||
{
|
||||
cache.Add(mediaController, mediaControllerViewModel);
|
||||
await mediator.PublishAsync(new Created<MediaControllerViewModel>(mediaControllerViewModel),
|
||||
cancellationToken);
|
||||
//await mediator.PublishAsync(new Created<MediaControllerViewModel>(mediaControllerViewModel),
|
||||
// cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MediaControllerManager(IMediator mediator,
|
||||
{
|
||||
if (factory.Create(session) is MediaController mediaController)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<MediaController>(mediaController));
|
||||
//await mediator.PublishAsync(new Created<MediaController>(mediaController));
|
||||
cache.Add(new KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>(session, mediaController));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ public class PrimaryWidgetConfigurationHandler(IMediator mediator,
|
||||
{
|
||||
if (factory.Create(item) is IWidgetComponentViewModel value)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<IWidgetComponentViewModel>(value),
|
||||
await mediator.PublishAsync(Inserted<IWidgetComponentViewModel>
|
||||
.For<PrimaryWidgetViewModel>(item.Order, value),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public record Created<TValue>(TValue Value) : INotification;
|
||||
|
||||
public record Inserted<TValue>(int Index, TValue Value) : INotification;
|
||||
public record Created<TValue>(TValue Value, object Target) : INotification
|
||||
{
|
||||
public static Created<TValue> For<TTarget>(TValue value)
|
||||
{
|
||||
return new Created<TValue>(value, typeof(TTarget).Name);
|
||||
}
|
||||
}
|
||||
public record Inserted<TValue>(int Index, TValue Value, object Target) : INotification
|
||||
{
|
||||
public static Inserted<TValue> For<TTarget>(int index, TValue value)
|
||||
{
|
||||
return new Inserted<TValue>(index, value, typeof(TTarget).Name);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
IObservableCollectionViewModel<TItem>,
|
||||
INotificationHandler<Removed<TItem>>,
|
||||
INotificationHandler<Created<TItem>>,
|
||||
INotificationHandler<Inserted<TItem>>,
|
||||
IDisposable
|
||||
where TItem :
|
||||
IDisposable
|
||||
@@ -228,9 +229,26 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
public ValueTask Handle(Created<TItem> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is not null)
|
||||
if (notification.Target.Equals(GetType().Name))
|
||||
{
|
||||
Add(notification.Value);
|
||||
if (notification.Value is TItem item)
|
||||
{
|
||||
Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
public ValueTask Handle(Inserted<TItem> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Target.Equals(GetType().Name))
|
||||
{
|
||||
if (notification.Value is TItem item)
|
||||
{
|
||||
Insert(notification.Index, item);
|
||||
}
|
||||
}
|
||||
|
||||
return ValueTask.CompletedTask;
|
||||
|
||||
Reference in New Issue
Block a user