feat(ui): add ToggleDone command and checkbox state to TaskItemViewModel

This commit is contained in:
Mika Kuns
2026-04-14 10:21:47 +02:00
parent 3c52e9c67f
commit 0796b3c2d5

View File

@@ -20,9 +20,10 @@ public partial class TaskItemViewModel : ViewModelBase
private readonly Func<string, Task>? _runNow;
private readonly Func<bool> _canRunNow;
private readonly Func<string, Task>? _toggleDone;
public TaskItemViewModel(TaskEntity entity, IReadOnlyList<TagEntity> tags,
Func<string, Task>? runNow, Func<bool> canRunNow)
Func<string, Task>? runNow, Func<bool> canRunNow, Func<string, Task>? toggleDone = null)
{
Entity = entity;
Id = entity.Id;
@@ -35,8 +36,13 @@ public partial class TaskItemViewModel : ViewModelBase
_description = entity.Description;
_runNow = runNow;
_canRunNow = canRunNow;
_toggleDone = toggleDone;
}
public bool IsDone => Status == TaskStatus.Done;
public bool IsRunning => Status == TaskStatus.Running;
public bool CanToggleDone => Status != TaskStatus.Running && Status != TaskStatus.Failed;
public void Refresh(TaskEntity entity, IReadOnlyList<TagEntity> tags)
{
Entity = entity;
@@ -47,6 +53,10 @@ public partial class TaskItemViewModel : ViewModelBase
CommitType = entity.CommitType;
Description = entity.Description;
RunNowCommand.NotifyCanExecuteChanged();
OnPropertyChanged(nameof(IsDone));
OnPropertyChanged(nameof(IsRunning));
OnPropertyChanged(nameof(CanToggleDone));
ToggleDoneCommand.NotifyCanExecuteChanged();
}
[RelayCommand(CanExecute = nameof(CanRunNow))]
@@ -58,4 +68,11 @@ public partial class TaskItemViewModel : ViewModelBase
private bool CanRunNow() =>
_canRunNow() && Status == TaskStatus.Queued;
[RelayCommand(CanExecute = nameof(CanToggleDone))]
private async Task ToggleDone()
{
if (_toggleDone is not null)
await _toggleDone(Id);
}
}