1- using System . Collections . ObjectModel ;
2- using System . Windows ;
1+ using System . Windows ;
32using System . Windows . Controls ;
43using System . Windows . Input ;
54using Desktop . Tasks ;
65using Task = Desktop . Domain . Task ;
76
87namespace Desktop . Project ;
98
10- using SystemTask = System . Threading . Tasks . Task ;
11-
129public partial class TasksList : UserControl
1310{
1411 private readonly ITaskRepository taskRepository ;
1512 private readonly TaskListViewModel viewModel ;
1613 private readonly TaskCreationViewModel taskCreationViewModel ;
17- private readonly ObservableCollection < Task > tasks = [ ] ;
1814
1915 public TasksList (
2016 ITaskRepository taskRepository ,
@@ -26,23 +22,16 @@ public TasksList(
2622 this . taskCreationViewModel = taskCreationViewModel ;
2723
2824 InitializeComponent ( ) ;
29- Tasks . ItemsSource = tasks ;
25+ Tasks . ItemsSource = viewModel . Tasks ;
3026
31- // TODO: load this async and deferred from the ctor.
32- var retrievedTasks = SystemTask . Run ( taskRepository . All ) . Result ;
33- foreach ( var task in retrievedTasks )
34- tasks . Add ( task ) ;
27+ viewModel . PopulateTasks ( ) ;
3528 }
3629
3730 private void Add ( object sender , RoutedEventArgs e )
3831 {
39- var taskCreationWindow = new TaskCreation ( taskCreationViewModel ) ;
40- taskCreationWindow . ShowDialog ( ) ;
41-
42- if ( taskCreationWindow . CreatedTask is null )
43- return ;
32+ new TaskCreation ( taskCreationViewModel ) . ShowDialog ( ) ;
4433
45- tasks . Add ( taskCreationWindow . CreatedTask ) ;
34+ viewModel . Add . Execute ( taskCreationViewModel ) ;
4635 }
4736
4837 private void Edit ( object sender , MouseButtonEventArgs e )
@@ -61,7 +50,7 @@ private void Delete(object sender, RoutedEventArgs e)
6150
6251 var toRemove = button . DataContext as Task ;
6352
64- tasks . Remove ( toRemove ! ) ;
53+ viewModel . Tasks . Remove ( toRemove ! ) ;
6554 taskRepository . Delete ( toRemove ! ) ;
6655 }
6756}
0 commit comments