From 6634e21361c1dda4e9b774d627077eff1fff2cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agn=C3=A8s=20Zitte?= Date: Mon, 2 May 2022 09:40:13 -0400 Subject: [PATCH] fix: UI fixes and add some missing binding/logic for TaskPage and TaskListPage --- ...nverter.cs => TaskListToValueConverter.cs} | 2 +- src/ToDo.UI/ToDo.UI.projitems | 2 +- src/ToDo.UI/Views/HomePage.xaml | 22 ++++---- src/ToDo.UI/Views/SearchPage.xaml | 4 +- src/ToDo.UI/Views/TaskControl.xaml | 18 ++++--- src/ToDo.UI/Views/TaskListPage.xaml | 52 ++++++++++--------- src/ToDo/Business/TaskService.cs | 2 +- src/ToDo/Data/TaskBodyData.cs | 2 +- src/ToDo/Presentation/HomeViewModel.cs | 14 ++--- src/ToDo/Presentation/TaskListViewModel.cs | 20 +++---- src/ToDo/Presentation/TaskViewModel.cs | 6 +-- 11 files changed, 69 insertions(+), 75 deletions(-) rename src/ToDo.UI/Converters/{TaskListIconConverter.cs => TaskListToValueConverter.cs} (92%) diff --git a/src/ToDo.UI/Converters/TaskListIconConverter.cs b/src/ToDo.UI/Converters/TaskListToValueConverter.cs similarity index 92% rename from src/ToDo.UI/Converters/TaskListIconConverter.cs rename to src/ToDo.UI/Converters/TaskListToValueConverter.cs index a620aa37..49f96b76 100644 --- a/src/ToDo.UI/Converters/TaskListIconConverter.cs +++ b/src/ToDo.UI/Converters/TaskListToValueConverter.cs @@ -4,7 +4,7 @@ namespace ToDo.Converters { - public class TaskListIconConverter : IValueConverter + public class TaskListToValueConverter : IValueConverter { public object? ImportantValue { get; set; } public object? TasksValue { get; set; } diff --git a/src/ToDo.UI/ToDo.UI.projitems b/src/ToDo.UI/ToDo.UI.projitems index 4dc4d3cf..a9521c53 100644 --- a/src/ToDo.UI/ToDo.UI.projitems +++ b/src/ToDo.UI/ToDo.UI.projitems @@ -27,7 +27,7 @@ App.xaml - + AddListFlyout.xaml diff --git a/src/ToDo.UI/Views/HomePage.xaml b/src/ToDo.UI/Views/HomePage.xaml index c3d44c44..3bff518b 100644 --- a/src/ToDo.UI/Views/HomePage.xaml +++ b/src/ToDo.UI/Views/HomePage.xaml @@ -24,15 +24,15 @@ 280 800 - + - + - + @@ -111,7 +112,8 @@ - + diff --git a/src/ToDo.UI/Views/SearchPage.xaml b/src/ToDo.UI/Views/SearchPage.xaml index 721e8869..dfed5eb0 100644 --- a/src/ToDo.UI/Views/SearchPage.xaml +++ b/src/ToDo.UI/Views/SearchPage.xaml @@ -108,11 +108,11 @@ utu:AutoLayout.CounterAlignment="Start" Style="{StaticResource MaterialToggleButtonIconStyle}"> - - diff --git a/src/ToDo.UI/Views/TaskControl.xaml b/src/ToDo.UI/Views/TaskControl.xaml index 53dcc973..91636432 100644 --- a/src/ToDo.UI/Views/TaskControl.xaml +++ b/src/ToDo.UI/Views/TaskControl.xaml @@ -4,12 +4,11 @@ xmlns:local="using:ToDo.Views" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" xmlns:uen="using:Uno.Extensions.Navigation.UI" xmlns:uer="using:Uno.Extensions.Reactive.UI" xmlns:utu="using:Uno.Toolkit.UI" - xmlns:um="using:Uno.Material"> - + xmlns:um="using:Uno.Material" + mc:Ignorable="d"> F1 M 14 1.4099998474121094 L 12.59000015258789 0 L 7 5.590000152587891 L 1.4099998474121094 0 L 0 1.4099998474121094 L 5.590000152587891 7 L 0 12.59000015258789 L 1.4099998474121094 14 L 7 8.40999984741211 L 12.59000015258789 14 L 14 12.59000015258789 L 8.40999984741211 7 L 14 1.4099998474121094 Z @@ -21,7 +20,7 @@ - - @@ -48,10 +48,10 @@ Command="{Binding ToggleIsImportant}" CommandParameter="{Binding}"> - + - + @@ -133,6 +133,7 @@ diff --git a/src/ToDo.UI/Views/TaskListPage.xaml b/src/ToDo.UI/Views/TaskListPage.xaml index d5c286fe..9a567b46 100644 --- a/src/ToDo.UI/Views/TaskListPage.xaml +++ b/src/ToDo.UI/Views/TaskListPage.xaml @@ -5,15 +5,20 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:ToDo.Controls" + xmlns:converters="using:ToDo.Converters" xmlns:uen="using:Uno.Extensions.Navigation.UI" xmlns:uer="using:Uno.Extensions.Reactive.UI" xmlns:utu="using:Uno.Toolkit.UI" xmlns:um="using:Uno.Material" mc:Ignorable="d" - NavigationCacheMode="Required" - Background="{ThemeResource MaterialPrimaryVariantLightBrush}"> + NavigationCacheMode="Required"> + + F1 M 14 8 L 8 8 L 8 14 L 6 14 L 6 8 L 0 8 L 0 6 L 6 6 L 6 0 L 8 0 L 8 6 L 14 6 L 14 8 Z F1 M 1 16 C 1 17.100000023841858 1.899999976158142 18 3 18 L 11 18 C 12.100000023841858 18 13 17.100000023841858 13 16 L 13 4 L 1 4 L 1 16 Z M 3 6 L 11 6 L 11 16 L 3 16 L 3 6 Z M 10.5 1 L 9.5 0 L 4.5 0 L 3.5 1 L 0 1 L 0 3 L 14 3 L 14 1 L 10.5 1 Z F1 M 15.40999984741211 1.7950000762939453 L 14.200000762939453 0.5849999785423279 C 13.420000791549683 -0.19499999284744263 12.149999856948853 -0.19499999284744263 11.369999885559082 0.5849999785423279 L 8.6899995803833 3.2649998664855957 L 0 11.954999923706055 L 0 15.994999885559082 L 4.039999961853027 15.994999885559082 L 12.779999732971191 7.255000114440918 L 15.40999984741211 4.625 C 16.19999986886978 3.8450000286102295 16.19999986886978 2.575000047683716 15.40999984741211 1.7950000762939453 L 15.40999984741211 1.7950000762939453 Z M 3.2100000381469727 13.994999885559082 L 2 13.994999885559082 L 2 12.785000801086426 L 10.65999984741211 4.125 L 11.869999885559082 5.335000038146973 L 3.2100000381469727 13.994999885559082 Z M 8 15.994999885559082 L 12 11.994999885559082 L 18 11.994999885559082 L 18 15.994999885559082 L 8 15.994999885559082 Z @@ -85,11 +90,11 @@ CommandParameter="{Binding}" Style="{StaticResource MaterialToggleButtonIconStyle}"> - - @@ -106,7 +111,7 @@ - + @@ -137,9 +142,8 @@ - @@ -168,7 +172,7 @@ uen:Region.Attached="True" uen:Region.Name="MultiTaskLists"> - - + + + - - - - - + + - - diff --git a/src/ToDo/Business/TaskService.cs b/src/ToDo/Business/TaskService.cs index 90180212..4392d66a 100644 --- a/src/ToDo/Business/TaskService.cs +++ b/src/ToDo/Business/TaskService.cs @@ -37,7 +37,7 @@ public async Task DeleteAsync(ToDoTask task, CancellationToken ct) { await _client.DeleteAsync(task.ListId, task.Id, ct); - _messenger.Send(new EntityMessage(EntityChange.Delete, task), task.ListId); + _messenger.Send(new EntityMessage(EntityChange.Delete, task)); } /// diff --git a/src/ToDo/Data/TaskBodyData.cs b/src/ToDo/Data/TaskBodyData.cs index 71e5f541..bdf3a9ed 100644 --- a/src/ToDo/Data/TaskBodyData.cs +++ b/src/ToDo/Data/TaskBodyData.cs @@ -1,6 +1,6 @@ namespace ToDo; -public class TaskBodyData +public record TaskBodyData { [JsonPropertyName("content")] public string? Content { get; set; } diff --git a/src/ToDo/Presentation/HomeViewModel.cs b/src/ToDo/Presentation/HomeViewModel.cs index 9f004c3e..5d209087 100644 --- a/src/ToDo/Presentation/HomeViewModel.cs +++ b/src/ToDo/Presentation/HomeViewModel.cs @@ -15,15 +15,13 @@ private HomeViewModel( INavigator navigator, ITaskListService listSvc, IMessenger messenger, - ICommandBuilder createTaskList, - ICommandBuilder navigateToTaskList) + ICommandBuilder createTaskList) { _navigator = navigator; _logger = logger; _listSvc = listSvc; createTaskList.Execute(CreateTaskList); - navigateToTaskList.Execute(NavigateToTaskList); Lists.Observe(messenger, list => list.Id); } @@ -47,8 +45,8 @@ private HomeViewModel( private async ValueTask CreateTaskList(CancellationToken ct) { - var response = await _navigator.NavigateViewModelForResultAsync(this,qualifier: Qualifiers.Dialog, cancellation: ct); - if(response is null) + var response = await _navigator.NavigateViewModelForResultAsync(this, qualifier: Qualifiers.Dialog, cancellation: ct); + if (response is null) { return; } @@ -61,10 +59,4 @@ private async ValueTask CreateTaskList(CancellationToken ct) await _listSvc.CreateAsync(listName, ct); } } - - private async ValueTask NavigateToTaskList(TaskListData list, CancellationToken ct) - { - // TODO: Nav - Could this be an implicit nav? - await _navigator.NavigateViewModelAsync(this, data: list, cancellation: ct); - } } diff --git a/src/ToDo/Presentation/TaskListViewModel.cs b/src/ToDo/Presentation/TaskListViewModel.cs index b5b51122..d17df42e 100644 --- a/src/ToDo/Presentation/TaskListViewModel.cs +++ b/src/ToDo/Presentation/TaskListViewModel.cs @@ -8,7 +8,7 @@ public partial class TaskListViewModel : IRecipient> private readonly INavigator _navigator; private readonly ITaskListService _listSvc; private readonly ITaskService _taskSvc; - private readonly IState _entity; + private readonly IInput _entity; private readonly ILogger _logger; private TaskListViewModel( @@ -20,7 +20,6 @@ private TaskListViewModel( IInput entity, ICommandBuilder createTask, ICommandBuilder toggleIsImportant, - ICommandBuilder navigateToTask, ICommandBuilder toggleIsCompleted, ICommandBuilder deleteList, ICommandBuilder renameList) @@ -33,7 +32,6 @@ private TaskListViewModel( createTask.Given(entity).Then(CreateTask); toggleIsImportant.Then(ToggleIsImportant); - navigateToTask.Then(NavigateToTask); toggleIsCompleted.Then(ToggleIsCompleted); deleteList.Given(entity).Then(DeleteList); renameList.Given(entity).Then(RenameList); @@ -57,7 +55,7 @@ private async ValueTask CreateTask(TaskList list, CancellationToken ct) } var result = await response.Result; - + var taskName = result.SomeOrDefault()?.Title; if (taskName is not null) { @@ -77,12 +75,6 @@ private async ValueTask ToggleIsImportant (ToDoTask task, CancellationToken ct) await _taskSvc.UpdateAsync(updatedTask, ct); } - private async ValueTask NavigateToTask(ToDoTask task, CancellationToken ct) - { - // TODO: Nav - Could this be an implicit nav? - await _navigator.NavigateViewModelAsync(this, data: task, cancellation: ct); - } - private async ValueTask DeleteList(TaskList list, CancellationToken ct) { var response = await _navigator.NavigateRouteForResultAsync(this, "ConfirmDeleteList", qualifier: Qualifiers.Dialog, cancellation: ct); @@ -119,8 +111,12 @@ private async ValueTask RenameList(TaskList list, CancellationToken ct) return; } - var newListName = await response.Result; - // TODO: Rename the list + var newListName = (await response.Result).SomeOrDefault(); + if (!String.IsNullOrWhiteSpace(newListName)) + { + list = list with { DisplayName = newListName }; + await _listSvc.UpdateAsync(list, ct); + } } diff --git a/src/ToDo/Presentation/TaskViewModel.cs b/src/ToDo/Presentation/TaskViewModel.cs index 96abc54c..670b7023 100644 --- a/src/ToDo/Presentation/TaskViewModel.cs +++ b/src/ToDo/Presentation/TaskViewModel.cs @@ -51,7 +51,7 @@ private async ValueTask Delete(ToDoTask task, CancellationToken ct) private async ValueTask AddTaskNote(ToDoTask task, CancellationToken ct) { - var response = await _navigator.NavigateViewModelForResultAsync(this, cancellation: ct); + var response = await _navigator.NavigateViewModelForResultAsync(this, data: task, cancellation: ct); if (response is null) { return; @@ -62,9 +62,7 @@ private async ValueTask AddTaskNote(ToDoTask task, CancellationToken ct) var note = result.SomeOrDefault()?.Content; if (note is not null) { - // TODO: Switch to this code when compilation issue is fixed with source generation - //var updatedNote = task.Body is not null ? task.Body with { Content = note } : new TaskBodyData { Content = note }; - var updatedNote = task.Body ?? new TaskBodyData(); + var updatedNote = task.Body is not null ? task.Body with { Content = note } : new TaskBodyData { Content = note }; updatedNote.Content = note; var updatedTask = task with { Body = updatedNote };