44
55namespace MAUITodo . Views ;
66
7- public partial class TodoListPage : ContentPage
7+ public partial class TodoListPage
88{
99 private readonly PowerSyncData database ;
1010 private readonly TodoList selectedList ;
@@ -38,11 +38,11 @@ protected override async void OnAppearing()
3838
3939 private async void OnAddClicked ( object sender , EventArgs e )
4040 {
41- string description = await DisplayPromptAsync ( "New Todo" , "Enter todo description:" ) ;
41+ var description = await DisplayPromptAsync ( "New Todo" , "Enter todo description:" ) ;
4242 if ( ! string . IsNullOrWhiteSpace ( description ) )
4343 {
44- var todo = new TodoItem
45- {
44+ var todo = new TodoItem
45+ {
4646 Description = description ,
4747 ListId = selectedList . ID
4848 } ;
@@ -52,30 +52,30 @@ private async void OnAddClicked(object sender, EventArgs e)
5252
5353 private async void OnDeleteClicked ( object sender , EventArgs e )
5454 {
55- var button = ( Button ) sender ;
56- var todo = ( TodoItem ) button . CommandParameter ;
57-
58- bool confirm = await DisplayAlert ( "Confirm Delete" ,
59- $ "Are you sure you want to delete '{ todo . Description } '?",
60- "Yes" , "No" ) ;
61-
62- if ( confirm )
55+ if ( sender is Button button && button . CommandParameter is TodoItem todo )
6356 {
64- await database . DeleteItemAsync ( todo ) ;
57+ var confirm = await DisplayAlert ( "Confirm Delete" ,
58+ $ "Are you sure you want to delete '{ todo . Description } '?",
59+ "Yes" , "No" ) ;
60+
61+ if ( confirm )
62+ {
63+ await database . DeleteItemAsync ( todo ) ;
64+ }
6565 }
6666 }
6767
6868 private async void OnCheckBoxChanged ( object sender , CheckedChangedEventArgs e )
6969 {
70- if ( sender is CheckBox checkBox &&
71- checkBox . Parent ? . Parent ? . BindingContext is TodoItem todo )
70+ if ( sender is CheckBox checkBox && checkBox . Parent ? . Parent ? . BindingContext is TodoItem todo )
7271 {
73- if ( e . Value == true && todo . CompletedAt == null )
72+ if ( e . Value && todo . CompletedAt == null )
7473 {
7574 todo . Completed = e . Value ;
76- todo . CompletedAt = DateTime . UtcNow . ToString ( "o " ) ;
75+ todo . CompletedAt = DateTime . UtcNow . ToString ( "yyyy-MM-dd HH:mm:ss " ) ;
7776 await database . SaveItemAsync ( todo ) ;
78- } else if ( e . Value == false && todo . CompletedAt != null )
77+ }
78+ else if ( e . Value == false && todo . CompletedAt != null )
7979 {
8080 todo . Completed = e . Value ;
8181 todo . CompletedAt = null ; // Uncheck, clear completed time
@@ -88,16 +88,16 @@ private async void OnItemSelected(object sender, SelectionChangedEventArgs e)
8888 {
8989 if ( e . CurrentSelection . FirstOrDefault ( ) is TodoItem selectedItem )
9090 {
91- string newDescription = await DisplayPromptAsync ( "Edit Todo" ,
92- "Enter new description:" ,
91+ var newDescription = await DisplayPromptAsync ( "Edit Todo" ,
92+ "Enter new description:" ,
9393 initialValue : selectedItem . Description ) ;
94-
94+
9595 if ( ! string . IsNullOrWhiteSpace ( newDescription ) )
9696 {
9797 selectedItem . Description = newDescription ;
9898 await database . SaveItemAsync ( selectedItem ) ;
9999 }
100-
100+
101101 TodoItemsCollection . SelectedItem = null ;
102102 }
103103 }
0 commit comments