Massive improvements to notes/commenting

This commit is contained in:
TheXamlGuy
2024-07-15 21:51:13 +01:00
parent d93fc66e59
commit b84e3abef6
3 changed files with 34 additions and 5 deletions
+12
View File
@@ -30,5 +30,17 @@ public partial class CommentEntryCollectionViewModel(IServiceProvider provider,
return Task.CompletedTask;
}
protected override void OnStateChanged()
{
if (State is ItemState.Write)
{
Add<CreateCommentEntryViewModel>();
}
else
{
RemoveAt(Count - 1);
}
}
}
@@ -11,15 +11,18 @@ public class CommentEntryCollectionViewModelHandler(IServiceFactory serviceFacto
if (args.Sender is CommentEntryCollectionConfiguration configuration)
{
string? label = configuration.Label;
List<Comment> value = new List<Comment>();
List<Comment> values = configuration.Value is not null ? new List<Comment>(configuration.Value) : [];
double? width = configuration.Width;
if (serviceFactory.Create<CommentEntryCollectionViewModel>(args => args.Initialize(),
[.. args.Parameters, configuration, label, value, false, false, width])
[.. args.Parameters, configuration, label, values, false, false, width])
is CommentEntryCollectionViewModel viewModel)
{
foreach (Comment value in values.OrderByDescending(x => x.DateTime))
{
viewModel.Add<CommentEntryViewModel>(value.DateTime, value.Text);
}
viewModel.Add<CreateCommentEntryViewModel>();
return Task.FromResult<IItemEntryViewModel?>(viewModel);
}
}
+16 -2
View File
@@ -77,22 +77,36 @@ public partial class ItemEntryCollectionViewModel<TItem, TValue> :
Track(nameof(Value), () => Value, x => Value = x);
}
public Task Handle(UpdateEventArgs<Item> args) =>
Task.FromResult(State = ItemState.Write);
public Task Handle(UpdateEventArgs<Item> args)
{
State = ItemState.Write;
OnStateChanged();
return Task.CompletedTask;
}
public Task Handle(CancelEventArgs<Item> args)
{
Revert();
State = ItemState.Read;
OnStateChanged();
return Task.CompletedTask;
}
protected virtual void OnStateChanged()
{
}
public Task Handle(ConfirmEventArgs<Item> args)
{
Commit();
State = ItemState.Read;
OnStateChanged();
return Task.CompletedTask;
}