fix(ui): address code review findings
- Fix event handler leak in TaskDetailView.OnDataContextChanged (unsubscribe from previous ViewModel before subscribing to new one) - Move FormatFile call off UI thread with Task.Run to prevent freeze on large log files Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -90,7 +90,7 @@ public partial class TaskDetailViewModel : ViewModelBase
|
|||||||
&& File.Exists(task.LogPath))
|
&& File.Exists(task.LogPath))
|
||||||
{
|
{
|
||||||
_formatter = new StreamLineFormatter();
|
_formatter = new StreamLineFormatter();
|
||||||
LiveText = _formatter.FormatFile(task.LogPath);
|
LiveText = await Task.Run(() => _formatter.FormatFile(task.LogPath));
|
||||||
}
|
}
|
||||||
StatusText = task.Status.ToString().ToLowerInvariant();
|
StatusText = task.Status.ToString().ToLowerInvariant();
|
||||||
StatusChoice = task.Status.ToString();
|
StatusChoice = task.Status.ToString();
|
||||||
|
|||||||
@@ -33,13 +33,16 @@ public partial class TaskDetailView : UserControl
|
|||||||
this.FindControl<TextBox>("TitleBox")?.Focus();
|
this.FindControl<TextBox>("TitleBox")?.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TaskDetailViewModel? _previousVm;
|
||||||
|
|
||||||
protected override void OnDataContextChanged(EventArgs e)
|
protected override void OnDataContextChanged(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnDataContextChanged(e);
|
base.OnDataContextChanged(e);
|
||||||
if (DataContext is TaskDetailViewModel vm)
|
if (_previousVm is not null)
|
||||||
{
|
_previousVm.PropertyChanged -= OnViewModelPropertyChanged;
|
||||||
vm.PropertyChanged += OnViewModelPropertyChanged;
|
_previousVm = DataContext as TaskDetailViewModel;
|
||||||
}
|
if (_previousVm is not null)
|
||||||
|
_previousVm.PropertyChanged += OnViewModelPropertyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user