Skip to content

Commit 939463c

Browse files
committed
refactor: move Task editing responsibility to its own view model
1 parent c11ece4 commit 939463c

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

Desktop/Tasks/TaskEditing.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ namespace Desktop.Tasks;
77

88
public partial class TaskEditing : Window
99
{
10+
private readonly TaskEditingViewModel viewModel;
11+
1012
public TaskEditing(Task original)
1113
{
1214
InitializeComponent();
1315

14-
this.original = original;
16+
viewModel = new TaskEditingViewModel(original);
17+
1518
Name.Text = original.Name;
1619
Description.Text = original.Description;
1720
}
1821

19-
private readonly Task original;
20-
2122
private void SaveTask(object sender, RoutedEventArgs e)
2223
{
23-
original.Name = Name.Text;
24-
original.Description = Description.Text;
24+
viewModel.Save.Execute((Name.Text, Description.Text));
2525

2626
Close();
2727
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Windows.Input;
2+
using CommunityToolkit.Mvvm.Input;
3+
using Desktop.Common;
4+
using Task = Desktop.Domain.Task;
5+
6+
namespace Desktop.Tasks;
7+
8+
public class TaskEditingViewModel : ViewModelBase
9+
{
10+
private readonly Task taskBeingEdited;
11+
12+
public TaskEditingViewModel(Task taskBeingEdited)
13+
{
14+
this.taskBeingEdited = taskBeingEdited;
15+
16+
Save = new RelayCommand<(string, string)>(args =>
17+
{
18+
var (name, description) = args;
19+
20+
taskBeingEdited.Name = name;
21+
taskBeingEdited.Description = description;
22+
});
23+
}
24+
25+
public ICommand Save { get; }
26+
}

0 commit comments

Comments
 (0)