Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: UI fixes and add some missing binding/logic for TaskPage and TaskListPage #188

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/ToDo.UI/ToDo.UI.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<Compile Include="$(MSBuildThisFileDirectory)App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Converters\TaskListIconConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\TaskListToValueConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Dialogs\AddListFlyout.xaml.cs">
<DependentUpon>AddListFlyout.xaml</DependentUpon>
</Compile>
Expand Down
22 changes: 12 additions & 10 deletions src/ToDo.UI/Views/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<x:Double x:Key="SplitModeSidePaneWidth">280</x:Double>
<x:Double x:Key="SplitModeThresholdWidth">800</x:Double>

<converters:TaskListIconConverter x:Key="TaskListIconConverter"
ImportantValue="{StaticResource Icon_Star_Rate}"
TasksValue="{StaticResource Icon_House_Siding}"
DefaultValue="{StaticResource Icon_List}" />
<converters:TaskListToValueConverter x:Key="TaskListIconValueConverter"
ImportantValue="{StaticResource Icon_Star_Rate}"
TasksValue="{StaticResource Icon_House_Siding}"
DefaultValue="{StaticResource Icon_List}" />

<converters:TaskListIconConverter x:Key="TaskListIconForegroundConverter"
ImportantValue="{StaticResource MaterialErrorBrush}"
TasksValue="{StaticResource MaterialPrimaryVariantDarkBrush}"
DefaultValue="{StaticResource MaterialPrimaryVariantLightBrush}" />
<converters:TaskListToValueConverter x:Key="TaskListIconForegroundConverter"
ImportantValue="{StaticResource MaterialErrorBrush}"
TasksValue="{StaticResource MaterialPrimaryVariantDarkBrush}"
DefaultValue="{StaticResource MaterialPrimaryVariantLightBrush}" />
</Page.Resources>

<muxc:NavigationView x:Name="NavView"
Expand Down Expand Up @@ -89,7 +89,8 @@
uen:Navigation.Request="./TaskList"
uen:Navigation.Data="{Binding}">
<muxc:NavigationViewItem.Icon>
<PathIcon Data="{Binding Converter={StaticResource TaskListIconConverter}}" Foreground="{Binding Converter={StaticResource TaskListIconForegroundConverter}}" />
<PathIcon Data="{Binding Converter={StaticResource TaskListIconValueConverter}}"
Foreground="{Binding Converter={StaticResource TaskListIconForegroundConverter}}" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
</DataTemplate>
Expand All @@ -111,7 +112,8 @@
</Border>
</muxc:NavigationView.PaneFooter>

<Grid uen:Region.Navigator="Visibility" uen:Region.Attached="True" />
<Grid uen:Region.Navigator="Visibility"
uen:Region.Attached="True" />
</muxc:NavigationView>

</Page>
4 changes: 2 additions & 2 deletions src/ToDo.UI/Views/SearchPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
utu:AutoLayout.CounterAlignment="Start"
Style="{StaticResource MaterialToggleButtonIconStyle}">
<ToggleButton.Content>
<PathIcon Foreground="{StaticResource MaterialPrimaryVariantLightBrush}"
<PathIcon Foreground="{StaticResource MaterialOnSurfaceLowBrush}"
Data="{StaticResource Icon_Star_Rate}" />
</ToggleButton.Content>
<um:ControlExtensions.AlternateContent>
<PathIcon Foreground="{StaticResource MaterialOnSurfaceLowBrush}"
<PathIcon Foreground="{StaticResource MaterialPrimaryVariantLightBrush}"
Data="{StaticResource Icon_Star_Rate}" />
</um:ControlExtensions.AlternateContent>
</ToggleButton>
Expand Down
18 changes: 10 additions & 8 deletions src/ToDo.UI/Views/TaskControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<UserControl.Resources>
<x:String x:Key="Icon_Close">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</x:String>
Expand All @@ -21,7 +20,7 @@

<utu:AutoLayout Background="{ThemeResource MaterialSurfaceBrush}">
<utu:AutoLayout utu:AutoLayout.PrimaryAlignment="Stretch">
<utu:NavigationBar Content="Task"
<utu:NavigationBar Content="{Binding Entity.Title}"
Style="{StaticResource MaterialModalNavigationBarStyle}" />
<utu:AutoLayout Spacing="10"
Padding="0,10,0,0"
Expand All @@ -38,7 +37,8 @@
</utu:AutoLayout>
<utu:AutoLayout utu:AutoLayout.CounterAlignment="Start"
utu:AutoLayout.PrimaryAlignment="Stretch">
<TextBox PlaceholderText="{Binding Entity.Title}"
<TextBox PlaceholderText="Task Name"
Text="{Binding Entity.Title}"
Style="{StaticResource MaterialFilledTextBoxStyle}" />
</utu:AutoLayout>
<utu:AutoLayout>
Expand All @@ -48,10 +48,10 @@
Command="{Binding ToggleIsImportant}"
CommandParameter="{Binding}">
<ToggleButton.Content>
<PathIcon Data="{StaticResource Icon_Star_Rate}" />
<PathIcon Data="{StaticResource Icon_Star_Rate_Empty}" />
</ToggleButton.Content>
<um:ControlExtensions.AlternateContent>
<PathIcon Data="{StaticResource Icon_Star_Rate_Empty}" />
<PathIcon Data="{StaticResource Icon_Star_Rate}" />
</um:ControlExtensions.AlternateContent>
</ToggleButton>
</utu:AutoLayout>
Expand Down Expand Up @@ -133,6 +133,7 @@
<utu:AutoLayout PrimaryAxisAlignment="End"
Orientation="Horizontal">
<Button Content="Open"
Command="{Binding AddTaskNote}"
utu:AutoLayout.CounterAlignment="Start"
Style="{StaticResource MaterialTextButtonStyle}" />
</utu:AutoLayout>
Expand All @@ -159,7 +160,8 @@
utu:AutoLayout.CounterAlignment="Center">
<utu:AutoLayout PrimaryAxisAlignment="End"
Orientation="Horizontal">
<Button utu:AutoLayout.CounterAlignment="Start"
<Button Command="{Binding Delete}"
utu:AutoLayout.CounterAlignment="Start"
Style="{StaticResource MaterialButtonIconStyle}">
<PathIcon Data="{StaticResource Icon_Delete_Outline}" />
</Button>
Expand Down
52 changes: 28 additions & 24 deletions src/ToDo.UI/Views/TaskListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<Page.Resources>
<converters:TaskListToValueConverter x:Key="TaskListBackgroundConverter"
ImportantValue="{StaticResource MaterialErrorBrush}"
TasksValue="{StaticResource MaterialPrimaryVariantLightBrush}"
DefaultValue="{StaticResource MaterialPrimaryVariantLightBrush}" />

<x:String x:Key="Icon_Add">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</x:String>
<x:String x:Key="Icon_Delete_Outline">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</x:String>
<x:String x:Key="Icon_Drive_File_Rename_Outline">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</x:String>
Expand Down Expand Up @@ -85,11 +90,11 @@
CommandParameter="{Binding}"
Style="{StaticResource MaterialToggleButtonIconStyle}">
<ToggleButton.Content>
<PathIcon Foreground="{StaticResource MaterialPrimaryVariantLightBrush}"
<PathIcon Foreground="{StaticResource MaterialOnSurfaceLowBrush}"
Data="{StaticResource Icon_Star_Rate}" />
</ToggleButton.Content>
<um:ControlExtensions.AlternateContent>
<PathIcon Foreground="{StaticResource MaterialOnSurfaceLowBrush}"
<PathIcon Foreground="{StaticResource MaterialPrimaryVariantLightBrush}"
Data="{StaticResource Icon_Star_Rate}" />
</um:ControlExtensions.AlternateContent>
</ToggleButton>
Expand All @@ -106,7 +111,7 @@

</Page.Resources>

<Grid>
<Grid Background="{Binding Entity.Value, Converter={StaticResource TaskListBackgroundConverter}}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Narrow" />
Expand Down Expand Up @@ -137,9 +142,8 @@
</Grid.ColumnDefinitions>
<utu:AutoLayout>
<utu:AutoLayout utu:AutoLayout.PrimaryAlignment="Stretch">
<utu:NavigationBar Content="Task List"
x:Uid="Body_NavigationBar"
Background="{ThemeResource MaterialPrimaryVariantLightBrush}"
<utu:NavigationBar Content="{Binding Entity.DisplayName}"
Background="{Binding Entity.Value, Converter={StaticResource TaskListBackgroundConverter}}"
Style="{StaticResource MaterialNavigationBarStyle}">
<utu:NavigationBar.MainCommand>
<AppBarButton Foreground="{ThemeResource MaterialOnPrimaryMediumBrush}">
Expand Down Expand Up @@ -168,7 +172,7 @@
uen:Region.Attached="True"
uen:Region.Name="MultiTaskLists">
<utu:AutoLayout utu:AutoLayout.PrimaryAlignment="Stretch">
<utu:TabBar Background="{ThemeResource MaterialPrimaryVariantLightBrush}"
<utu:TabBar Background="{Binding Entity.Value, Converter={StaticResource TaskListBackgroundConverter}}"
Style="{StaticResource MaterialTopTabBarStyle}"
uen:Region.Attached="True">
<utu:TabBarItem Content="To Do"
Expand Down Expand Up @@ -207,28 +211,28 @@
</DataTemplate>
</uer:FeedView>

<uer:FeedView Source="{Binding ActiveTasks}"
<!-- Since both FeedView are Visible at the moment we need a layer
in between because there are on top of each other -->
<Border Visibility="{Binding Path=Visibility, ElementName=ActiveTasks}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="{Binding Entity.Value, Converter={StaticResource TaskListBackgroundConverter}}" />

<uer:FeedView x:Name="ActiveTasks"
Source="{Binding ActiveTasks}"
utu:AutoLayout.CounterAlignment="Start"
utu:AutoLayout.PrimaryAlignment="Stretch"
uen:Region.Name="ToDo"
Visibility="Visible">
<DataTemplate>
<!-- Since both FeedView are Visible at the moment we need a background
because there are on top of each other -->
<Border VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="{ThemeResource MaterialPrimaryVariantLightBrush}">
<ListView ItemsSource="{Binding Data}"
uen:Navigation.Request="Task"
SelectionMode="None"
IsItemClickEnabled="True"
Style="{StaticResource TaskListViewStyle}">
</ListView>
</Border>
<ListView ItemsSource="{Binding Data}"
uen:Navigation.Request="Task"
SelectionMode="None"
IsItemClickEnabled="True"
Style="{StaticResource TaskListViewStyle}">
</ListView>
</DataTemplate>
</uer:FeedView>


</Grid>

</utu:AutoLayout>
Expand Down
2 changes: 1 addition & 1 deletion src/ToDo/Business/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task DeleteAsync(ToDoTask task, CancellationToken ct)
{
await _client.DeleteAsync(task.ListId, task.Id, ct);

_messenger.Send(new EntityMessage<ToDoTask>(EntityChange.Delete, task), task.ListId);
_messenger.Send(new EntityMessage<ToDoTask>(EntityChange.Delete, task));
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion src/ToDo/Data/TaskBodyData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ToDo;

public class TaskBodyData
public record TaskBodyData
{
[JsonPropertyName("content")]
public string? Content { get; set; }
Expand Down
14 changes: 3 additions & 11 deletions src/ToDo/Presentation/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ private HomeViewModel(
IAuthenticationService authSvc,
ITaskListService listSvc,
IMessenger messenger,
ICommandBuilder createTaskList,
ICommandBuilder<TaskListData> navigateToTaskList)
ICommandBuilder createTaskList)
{
_navigator = navigator;
_logger = logger;
Expand All @@ -28,7 +27,6 @@ private HomeViewModel(
_listSvc = listSvc;

createTaskList.Execute(CreateTaskList);
navigateToTaskList.Execute(NavigateToTaskList);

Lists.Observe(messenger, list => list.Id);
}
Expand All @@ -43,8 +41,8 @@ private HomeViewModel(

private async ValueTask CreateTaskList(CancellationToken ct)
{
var response = await _navigator.NavigateViewModelForResultAsync<AddListViewModel, TaskListRequestData>(this,qualifier: Qualifiers.Dialog, cancellation: ct);
if(response is null)
var response = await _navigator.NavigateViewModelForResultAsync<AddListViewModel, TaskListRequestData>(this, qualifier: Qualifiers.Dialog, cancellation: ct);
if (response is null)
{
return;
}
Expand All @@ -57,10 +55,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<TaskListViewModel>(this, data: list, cancellation: ct);
}
}
20 changes: 8 additions & 12 deletions src/ToDo/Presentation/TaskListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class TaskListViewModel : IRecipient<EntityMessage<ToDoTask>>
private readonly INavigator _navigator;
private readonly ITaskListService _listSvc;
private readonly ITaskService _taskSvc;
private readonly IState<TaskList> _entity;
private readonly IInput<TaskList> _entity;
private readonly ILogger _logger;

private TaskListViewModel(
Expand All @@ -20,7 +20,6 @@ private TaskListViewModel(
IInput<TaskList> entity,
ICommandBuilder createTask,
ICommandBuilder<ToDoTask> toggleIsImportant,
ICommandBuilder<ToDoTask> navigateToTask,
ICommandBuilder<ToDoTask> toggleIsCompleted,
ICommandBuilder deleteList,
ICommandBuilder renameList)
Expand All @@ -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);
Expand All @@ -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)
{
Expand All @@ -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<TaskViewModel>(this, data: task, cancellation: ct);
}

private async ValueTask DeleteList(TaskList list, CancellationToken ct)
{
var response = await _navigator.NavigateRouteForResultAsync<DialogAction>(this, "ConfirmDeleteList", qualifier: Qualifiers.Dialog, cancellation: ct);
Expand Down Expand Up @@ -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);
}

}

Expand Down
6 changes: 2 additions & 4 deletions src/ToDo/Presentation/TaskViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskNoteViewModel, TaskBodyData>(this, cancellation: ct);
var response = await _navigator.NavigateViewModelForResultAsync<TaskNoteViewModel, TaskBodyData>(this, data: task, cancellation: ct);
if (response is null)
{
return;
Expand All @@ -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 };
Expand Down