feat(ui): collapse parent task rows by default with granular row sync

This commit is contained in:
Mika Kuns
2026-06-25 13:48:08 +02:00
parent d80a57836c
commit 38defee3d8
6 changed files with 66 additions and 60 deletions

View File

@@ -88,6 +88,10 @@
<!-- Icon.ArrowOut — filled arrow for "open external" button -->
<StreamGeometry x:Key="Icon.ArrowOut">M13 4 H20 V11 H18 V7.4 L11.4 14 L10 12.6 L16.6 6 H13 Z M4 6 H10 V8 H6 V18 H16 V14 H18 V20 H4 Z</StreamGeometry>
<!-- Icon.ChevronRight / Icon.ChevronDown — filled expand/collapse chevrons (PathIcon fills) -->
<StreamGeometry x:Key="Icon.ChevronRight">M9 5 L16 12 L9 19 L6.8 16.8 L11.6 12 L6.8 7.2 Z</StreamGeometry>
<StreamGeometry x:Key="Icon.ChevronDown">M5 9 L12 16 L19 9 L16.8 6.8 L12 11.6 L7.2 6.8 Z</StreamGeometry>
<!-- Icon.Text — three filled horizontal bars (paragraph / description icon) -->
<StreamGeometry x:Key="Icon.Text">M4 6 H20 V8 H4 Z M4 11 H20 V13 H4 Z M4 16 H14 V18 H4 Z</StreamGeometry>

View File

@@ -301,27 +301,17 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
internal void Regroup()
{
OverdueItems.Clear();
OpenItems.Clear();
CompletedItems.Clear();
// Auto-collapse planning parents whose every child is Done (unless the user
// has explicitly toggled the row — saved state wins).
// Collapse parents that have children by default, so subtasks stay tucked away until
// the user expands the row (an explicit toggle is saved and wins over this default).
var childrenByParent = Items
.Where(r => r.IsChild && !string.IsNullOrEmpty(r.ParentTaskId))
.GroupBy(r => r.ParentTaskId!)
.ToDictionary(g => g.Key, g => g.ToList());
foreach (var parent in Items.Where(r => r.IsPlanningParent && !r.IsChild
&& r.PlanningPhase == PlanningPhase.Finalized
&& !r.Done))
foreach (var parent in Items.Where(r => r.IsPlanningParent && !r.IsChild && !r.Done))
{
if (_expandedState.ContainsKey(parent.Id)) continue;
if (childrenByParent.TryGetValue(parent.Id, out var kids)
&& kids.Count > 0
&& kids.All(c => c.Status == TaskStatus.Done))
{
if (childrenByParent.TryGetValue(parent.Id, out var kids) && kids.Count > 0)
parent.IsExpanded = false;
}
}
// Restore IsExpanded from saved state
@@ -362,19 +352,29 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
}
var today = DateTime.Today;
var overdue = new List<TaskRowViewModel>();
var open = new List<TaskRowViewModel>();
var completed = new List<TaskRowViewModel>();
foreach (var r in flat)
{
var underOpenPlanningParent = r.IsChild &&
flat.Any(p => p.Id == r.ParentTaskId && p.IsPlanningParent && !p.Done);
if (r.Done && !underOpenPlanningParent)
CompletedItems.Add(r);
completed.Add(r);
else if (r.ScheduledFor is { } d && d.Date < today)
OverdueItems.Add(r);
overdue.Add(r);
else
OpenItems.Add(r);
open.Add(r);
}
// Reconcile the bound collections in place (granular Insert/Move/Remove) rather than
// Clear+Add, so toggling a parent only touches its own child rows — the ItemsControl
// keeps every unchanged container instead of tearing the whole list down on a Reset.
SyncCollection(OverdueItems, overdue);
SyncCollection(OpenItems, open);
SyncCollection(CompletedItems, completed);
HasOverdue = OverdueItems.Count > 0;
HasOpen = OpenItems.Count > 0;
HasCompleted = CompletedItems.Count > 0;
@@ -500,6 +500,28 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
coll.Move(srcIdx, finalIdx);
}
// Reconcile a bound collection toward a target order using granular Remove/Move/Insert,
// so unchanged rows keep their containers (no Reset-driven full re-render).
private static void SyncCollection(
System.Collections.ObjectModel.ObservableCollection<TaskRowViewModel> dst,
List<TaskRowViewModel> target)
{
var keep = new HashSet<TaskRowViewModel>(target);
for (int i = dst.Count - 1; i >= 0; i--)
if (!keep.Contains(dst[i]))
dst.RemoveAt(i);
for (int i = 0; i < target.Count; i++)
{
var item = target[i];
if (i < dst.Count && ReferenceEquals(dst[i], item)) continue;
var cur = dst.IndexOf(item);
if (cur >= 0) dst.Move(cur, i);
else dst.Insert(i, item);
}
}
private System.Collections.ObjectModel.ObservableCollection<TaskRowViewModel>? SectionFor(TaskRowViewModel row)
{
if (OverdueItems.Contains(row)) return OverdueItems;

View File

@@ -87,10 +87,10 @@
VerticalAlignment="Center"
ToolTip.Tip="{loc:Tr tasks.toggleSubtasksTip}">
<Panel>
<TextBlock Classes="meta" Text="▾" IsVisible="{Binding IsExpanded}"
VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Classes="meta" Text="▸" IsVisible="{Binding !IsExpanded}"
VerticalAlignment="Center" HorizontalAlignment="Center"/>
<PathIcon Width="12" Height="12" Data="{StaticResource Icon.ChevronDown}"
Foreground="{DynamicResource TextDimBrush}" IsVisible="{Binding IsExpanded}"/>
<PathIcon Width="12" Height="12" Data="{StaticResource Icon.ChevronRight}"
Foreground="{DynamicResource TextDimBrush}" IsVisible="{Binding !IsExpanded}"/>
</Panel>
</Button>

View File

@@ -1,12 +1,7 @@
using System.Linq;
using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.VisualTree;
using ClaudeDo.Data.Models;
using ClaudeDo.Ui.ViewModels.Islands;
@@ -123,24 +118,4 @@ public partial class TaskRowView : UserControl
ScheduleAnchor.Flyout?.Hide();
_pendingScheduleRow = null;
}
protected override async void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
RenderTransform = new TranslateTransform(0, 8);
Opacity = 0;
var anim = new Avalonia.Animation.Animation
{
Duration = TimeSpan.FromMilliseconds(300),
Easing = new CubicEaseOut(),
Children =
{
new KeyFrame { Cue = new Cue(0), Setters = { new Setter(OpacityProperty, 0d) } },
new KeyFrame { Cue = new Cue(1), Setters = { new Setter(OpacityProperty, 1d) } },
}
};
await anim.RunAsync(this);
Opacity = 1;
RenderTransform = null;
}
}