Skip to content

Commit dfa9f18

Browse files
committed
fix(web): sweep to unsettle and wake sidebar threads
1 parent 18012db commit dfa9f18

4 files changed

Lines changed: 89 additions & 58 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
reduceSidebarProjectScopeMenuState,
3131
resolveAdjacentThreadId,
3232
resolveProjectStatusIndicator,
33-
resolveSettleSweepKeys,
33+
resolveSidebarSweepKeys,
3434
resolveSidebarStageBadgeLabel,
3535
resolveSidebarThreadSection,
3636
resolveSidebarRowAccessibility,
@@ -2015,19 +2015,19 @@ describe("sortPinnedThreadsForSidebar", () => {
20152015
});
20162016
});
20172017

2018-
describe("resolveSettleSweepKeys", () => {
2018+
describe("resolveSidebarSweepKeys", () => {
20192019
const ordered = ["a", "b", "c", "d", "blocked"];
20202020
const canSettle = (key: string) => key !== "blocked";
20212021

20222022
it("covers every row between the pressed row and the pointer, in either direction", () => {
2023-
expect(resolveSettleSweepKeys(ordered, "b", "b", canSettle)).toEqual(["b"]);
2024-
expect(resolveSettleSweepKeys(ordered, "b", "d", canSettle)).toEqual(["b", "c", "d"]);
2025-
expect(resolveSettleSweepKeys(ordered, "d", "a", canSettle)).toEqual(["a", "b", "c", "d"]);
2023+
expect(resolveSidebarSweepKeys(ordered, "b", "b", canSettle)).toEqual(["b"]);
2024+
expect(resolveSidebarSweepKeys(ordered, "b", "d", canSettle)).toEqual(["b", "c", "d"]);
2025+
expect(resolveSidebarSweepKeys(ordered, "d", "a", canSettle)).toEqual(["a", "b", "c", "d"]);
20262026
});
20272027

20282028
it("leaves out rows that cannot settle and rows that left the list", () => {
2029-
expect(resolveSettleSweepKeys(ordered, "c", "blocked", canSettle)).toEqual(["c", "d"]);
2030-
expect(resolveSettleSweepKeys(ordered, "gone", "a", canSettle)).toEqual([]);
2029+
expect(resolveSidebarSweepKeys(ordered, "c", "blocked", canSettle)).toEqual(["c", "d"]);
2030+
expect(resolveSidebarSweepKeys(ordered, "gone", "a", canSettle)).toEqual([]);
20312031
});
20322032
});
20332033

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,17 @@ export function resolveSidebarDropVerb(
274274
return "wake";
275275
}
276276

277-
/** Threads a settle sweep covers: the settleable rows from the row whose
278-
Settle was pressed to the row under the pointer, in sidebar order. */
279-
export function resolveSettleSweepKeys(
277+
/** Eligible rows between the pressed action and the pointer, in sidebar order. */
278+
export function resolveSidebarSweepKeys(
280279
orderedKeys: readonly string[],
281280
originKey: string,
282281
targetKey: string,
283-
canSettle: (key: string) => boolean,
282+
canApply: (key: string) => boolean,
284283
): string[] {
285284
const origin = orderedKeys.indexOf(originKey);
286285
const target = orderedKeys.indexOf(targetKey);
287286
if (origin === -1 || target === -1) return [];
288-
return orderedKeys
289-
.slice(Math.min(origin, target), Math.max(origin, target) + 1)
290-
.filter(canSettle);
287+
return orderedKeys.slice(Math.min(origin, target), Math.max(origin, target) + 1).filter(canApply);
291288
}
292289

293290
/** The thread row at a pointer height, clamped to the rows visible in the

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 77 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ import {
189189
planSidebarThreadDrop,
190190
reduceSidebarProjectScopeMenuState,
191191
resolveAdjacentThreadId,
192-
resolveSettleSweepKeys,
192+
resolveSidebarSweepKeys,
193193
resolveSidebarDropTarget,
194194
resolveSidebarDropVerb,
195195
resolveSidebarThreadSection,
@@ -710,9 +710,11 @@ function SidebarSectionPlaceholder(props: {
710710
}
711711

712712
// Pointer travel before a press on a row starts a drag, or a press on its
713-
// Settle button starts a settle sweep. Shorter presses stay clicks.
713+
// action button starts a sweep. Shorter presses stay clicks.
714714
const SIDEBAR_DRAG_DISTANCE = 6;
715715

716+
type SidebarSweepAction = "settle" | "unsettle" | "unsnooze";
717+
716718
// Zero-height markers reserve no label space at rest. During a drag the
717719
// sorting strategy opens 24px for a 16px label with 4px clearance on each side.
718720
const SIDEBAR_DRAG_LABEL_HEIGHT = 24;
@@ -1064,9 +1066,8 @@ const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {
10641066
const SidebarThreadRow = memo(function SidebarThreadRow(props: {
10651067
thread: SidebarThreadSummary;
10661068
variant: "card" | "slim";
1067-
// Slim rows are either settled (action: un-settle) or merely quiet
1068-
// (seen Ready threads — action: settle).
1069-
variantAction: "settle" | "unsettle" | "unsnooze";
1069+
// Settled rows un-settle, snoozed rows wake, and cards settle.
1070+
variantAction: SidebarSweepAction;
10701071
// False on environments whose server predates thread.settle/unsettle:
10711072
// the lifecycle affordances hide entirely rather than fail on click.
10721073
settlementSupported: boolean;
@@ -1090,8 +1091,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
10901091
// the pinned section. Any other position shows the verb badge instead, and
10911092
// the badge carries its own icon.
10921093
dragOverPinned: boolean;
1093-
// Inside a settle sweep's range: the row settles when the sweep is released.
1094-
settleArmed: boolean;
1094+
// The action this row will take when the sweep is released.
1095+
sweepAction: SidebarSweepAction | null;
10951096
// Compact wake countdown ("2h") for rows in the snoozed shelf.
10961097
snoozeWakeLabelText: string | null;
10971098
// When a snooze ended (timer or early wake); drives the Woke pill until
@@ -1117,7 +1118,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
11171118
renamingTitle: string;
11181119
onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void;
11191120
onSettle: (threadRef: ScopedThreadRef) => void;
1120-
onSettleSweepStart: (threadRef: ScopedThreadRef, event: PointerEvent) => void;
1121+
onActionSweepStart: (
1122+
threadRef: ScopedThreadRef,
1123+
action: SidebarSweepAction,
1124+
event: PointerEvent,
1125+
) => void;
11211126
onUnsettle: (threadRef: ScopedThreadRef) => void;
11221127
onSnooze: (threadRef: ScopedThreadRef, preset: Pick<SnoozePreset, "snoozedUntil">) => void;
11231128
onUnsnooze: (threadRef: ScopedThreadRef) => void;
@@ -1141,7 +1146,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
11411146
onFileDropThreads,
11421147
onRenameTitleChange,
11431148
onSettle,
1144-
onSettleSweepStart,
1149+
onActionSweepStart,
11451150
onSnooze,
11461151
onStartRename,
11471152
onThreadActivate,
@@ -1439,14 +1444,14 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
14391444
},
14401445
[onSettle, threadRef],
14411446
);
1442-
const handleSettlePointerDown = useCallback(
1447+
const handleActionPointerDown = useCallback(
14431448
(event: ReactPointerEvent) => {
14441449
if (!event.isPrimary || event.button !== 0) return;
1445-
// A press on Settle can become a settle sweep, so the row drag must not claim it.
1450+
// Action buttons sweep their section rather than picking up the row.
14461451
event.stopPropagation();
1447-
onSettleSweepStart(threadRef, event.nativeEvent);
1452+
onActionSweepStart(threadRef, variantAction, event.nativeEvent);
14481453
},
1449-
[onSettleSweepStart, threadRef],
1454+
[onActionSweepStart, threadRef, variantAction],
14501455
);
14511456
const handleUnsettleClick = useCallback(
14521457
(event: ReactMouseEvent) => {
@@ -1525,7 +1530,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15251530
variantAction === "unsettle" && "[&:not(:hover):not(:focus-within)_*]:text-secondary-label/70",
15261531
props.isActive
15271532
? "bg-sidebar-row-active text-sidebar-foreground"
1528-
: isSelected || props.settleArmed
1533+
: isSelected || props.sweepAction !== null
15291534
? "bg-sidebar-row-selected text-sidebar-foreground"
15301535
: hasUnsentDraft
15311536
? cn(draftSurfaceClassName, "text-sidebar-foreground")
@@ -1565,12 +1570,12 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15651570
...sortable.listeners,
15661571
}
15671572
: {};
1568-
// A row in a settle sweep wears the badge of a row dropped on Settled.
1573+
// Sweeps reuse the corresponding row-drop action badge.
15691574
const destinationVerb = sortable?.isDragging
15701575
? props.dropVerb
1571-
: props.settleArmed
1572-
? "settle"
1573-
: null;
1576+
: props.sweepAction === "unsnooze"
1577+
? "wake"
1578+
: props.sweepAction;
15741579
const dragDestination =
15751580
destinationVerb !== null ? (
15761581
<span
@@ -1778,7 +1783,12 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
17781783
{sortable?.isDragging ? (
17791784
dragDestination
17801785
) : (
1781-
<span className="relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end">
1786+
<span
1787+
className={cn(
1788+
"relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end",
1789+
props.sweepAction !== null && "hidden",
1790+
)}
1791+
>
17821792
<span
17831793
className={cn(
17841794
"inline-flex justify-end tabular-nums text-secondary-label transition-opacity",
@@ -1824,6 +1834,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
18241834
type="button"
18251835
aria-label="Wake thread now"
18261836
onClick={handleUnsnoozeClick}
1837+
onPointerDown={handleActionPointerDown}
18271838
className={cn(
18281839
"pointer-events-none absolute inset-y-0 right-0 -mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/sidebar-row:pointer-events-auto group-hover/sidebar-row:opacity-100",
18291840
isWoke && "group-hover/sidebar-row:static",
@@ -1840,6 +1851,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
18401851
type="button"
18411852
aria-label="Un-settle thread"
18421853
onClick={handleUnsettleClick}
1854+
onPointerDown={handleActionPointerDown}
18431855
className={cn(
18441856
"pointer-events-none absolute inset-y-0 right-0 -mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/sidebar-row:pointer-events-auto group-hover/sidebar-row:opacity-100",
18451857
isWoke && "group-hover/sidebar-row:static",
@@ -1856,6 +1868,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
18561868
type="button"
18571869
aria-label="Settle thread"
18581870
onClick={handleSettleClick}
1871+
onPointerDown={handleActionPointerDown}
18591872
className={cn(
18601873
"pointer-events-none absolute inset-y-0 right-0 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-2 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/sidebar-row:pointer-events-auto group-hover/sidebar-row:opacity-100",
18611874
isWoke && "group-hover/sidebar-row:static",
@@ -1866,6 +1879,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
18661879
)}
18671880
</span>
18681881
)}
1882+
{props.sweepAction !== null ? dragDestination : null}
18691883
{props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}
18701884
</TooltipTrigger>
18711885
{detailsTooltip}
@@ -1936,7 +1950,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
19361950
<span
19371951
className={cn(
19381952
"group/sidebar-status-slot relative ml-auto flex h-5 min-w-8 shrink-0 items-stretch justify-end text-xs",
1939-
props.settleArmed && "hidden",
1953+
props.sweepAction !== null && "hidden",
19401954
)}
19411955
>
19421956
{/* Read-only status labels yield to the hover actions. Woke is
@@ -2050,7 +2064,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
20502064
type="button"
20512065
aria-label="Settle thread"
20522066
onClick={handleSettleClick}
2053-
onPointerDown={handleSettlePointerDown}
2067+
onPointerDown={handleActionPointerDown}
20542068
className="-mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"
20552069
/>
20562070
}
@@ -2065,10 +2079,10 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
20652079
) : null}
20662080
</span>
20672081
)}
2068-
{/* A settle sweep hides the slot rather than unmounting it, so the
2069-
pressed Settle button stays connected and a cancelled sweep's
2082+
{/* A sweep hides the slot rather than unmounting it, so the
2083+
pressed action button stays connected and a cancelled sweep's
20702084
release click still fires and is consumed. */}
2071-
{props.settleArmed ? dragDestination : null}
2085+
{props.sweepAction !== null ? dragDestination : null}
20722086
</div>
20732087
<div className="mt-1 flex min-w-0">
20742088
{title}
@@ -3448,32 +3462,37 @@ export default function Sidebar() {
34483462
}, [activeThreads, pinnedThreads, settledThreads, snoozedThreads, workingThreads]);
34493463
const sectionByThreadKeyRef = useRef(sectionByThreadKey);
34503464
sectionByThreadKeyRef.current = sectionByThreadKey;
3451-
// Press Settle and drag up or down: every card in the pressed row's section
3452-
// between it and the pointer arms, and release settles them together like
3453-
// multi-select → Settle. Staying in one section keeps an overshoot from
3454-
// settling pinned threads, whose boundary is hidden outside a row drag. It
3465+
// Drag a row action to apply it to the armed rows in the same section.
3466+
// Staying in one section keeps an overshoot from changing neighboring
3467+
// sections, whose boundaries may be hidden outside a row drag. The sweep
34553468
// runs on the row drag's sensor and ref, so unmounting the list cancels it.
3456-
const [settleSweepKeys, setSettleSweepKeys] = useState<ReadonlySet<string> | null>(null);
3457-
const startSettleSweep = useCallback(
3458-
(threadRef: ScopedThreadRef, event: PointerEvent) => {
3469+
const [actionSweep, setActionSweep] = useState<{
3470+
action: SidebarSweepAction;
3471+
keys: ReadonlySet<string>;
3472+
} | null>(null);
3473+
const startActionSweep = useCallback(
3474+
(threadRef: ScopedThreadRef, action: SidebarSweepAction, event: PointerEvent) => {
34593475
const originKey = scopedThreadKey(threadRef);
34603476
const originSection = sectionByThreadKeyRef.current.get(originKey);
3461-
const canSettle = (key: string) => {
3477+
const canApply = (key: string) => {
34623478
const thread = threadByKeyRef.current.get(key);
3479+
const capabilities =
3480+
thread && serverConfigs.get(thread.environmentId)?.environment.capabilities;
34633481
return (
34643482
thread !== undefined &&
34653483
sectionByThreadKeyRef.current.get(key) === originSection &&
3466-
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSettlement ===
3467-
true
3484+
(action === "unsnooze"
3485+
? capabilities?.threadSnooze === true
3486+
: capabilities?.threadSettlement === true)
34683487
);
34693488
};
34703489
let targetKey: string | null = null;
34713490
let sweptKeys: string[] = [];
34723491
const sweepTo = (key: string | null) => {
34733492
if (key === null || key === targetKey) return;
34743493
targetKey = key;
3475-
sweptKeys = resolveSettleSweepKeys(orderedThreadKeysRef.current, originKey, key, canSettle);
3476-
setSettleSweepKeys(new Set(sweptKeys));
3494+
sweptKeys = resolveSidebarSweepKeys(orderedThreadKeysRef.current, originKey, key, canApply);
3495+
setActionSweep({ action, keys: new Set(sweptKeys) });
34773496
};
34783497
dragSensorRef.current = new SidebarPointerSensor({
34793498
active: originKey,
@@ -3483,22 +3502,34 @@ export default function Sidebar() {
34833502
onAttach: () => {},
34843503
onFinish: () => {
34853504
dragSensorRef.current = null;
3486-
setSettleSweepKeys(null);
3505+
setActionSweep(null);
34873506
},
34883507
},
34893508
onPending: () => {},
34903509
onStart: () => sweepTo(originKey),
34913510
onMove: ({ y }) =>
34923511
sweepTo(threadListRef.current && sidebarThreadKeyAtY(threadListRef.current, y)),
34933512
// Also runs after a press that never moved. Nothing is swept then,
3494-
// and the button's own click settles the row. Rows that changed
3513+
// and the button's own click applies its action. Rows that changed
34953514
// section mid-gesture, say pinned from another device, are skipped.
3496-
onEnd: () => settleThreads(sweptKeys.filter(canSettle)),
3515+
onEnd: () => {
3516+
const keys = sweptKeys.filter(canApply);
3517+
if (action === "settle") {
3518+
settleThreads(keys);
3519+
return;
3520+
}
3521+
for (const key of keys) {
3522+
const ref = parseScopedThreadKey(key);
3523+
if (ref === null) continue;
3524+
if (action === "unsettle") attemptUnsettle(ref);
3525+
else attemptUnsnooze(ref);
3526+
}
3527+
},
34973528
onCancel: () => {},
34983529
onAbort: () => {},
34993530
});
35003531
},
3501-
[serverConfigs, settleThreads],
3532+
[attemptUnsettle, attemptUnsnooze, serverConfigs, settleThreads],
35023533
);
35033534
const pinnedKeys = useMemo(
35043535
() =>
@@ -4995,10 +5026,10 @@ export default function Sidebar() {
49955026
className={cn(
49965027
"relative flex flex-col gap-px",
49975028
sidebarListItems.length > 0 && "flex-1",
4998-
// A settle sweep owns the pointer: rows it passes over
5029+
// An action sweep owns the pointer: rows it passes over
49995030
// neither show hover actions nor open tooltips, even
50005031
// controls that opt back in, like the Woke pill.
5001-
settleSweepKeys !== null && "**:pointer-events-none",
5032+
actionSweep !== null && "**:pointer-events-none",
50025033
)}
50035034
>
50045035
{(() => {
@@ -5055,7 +5086,9 @@ export default function Sidebar() {
50555086
dragOverPinned={
50565087
dragState?.activeKey === threadKey && dragTargetSection === "pinned"
50575088
}
5058-
settleArmed={settleSweepKeys?.has(threadKey) ?? false}
5089+
sweepAction={
5090+
actionSweep?.keys.has(threadKey) ? actionSweep.action : null
5091+
}
50595092
snoozeWakeLabelText={
50605093
section === "snoozed" && thread.snoozedUntil != null
50615094
? snoozeWakeLabel(thread.snoozedUntil, {
@@ -5104,7 +5137,7 @@ export default function Sidebar() {
51045137
renamingTitle={renamingThreadKey === threadKey ? renamingTitle : ""}
51055138
onContextMenu={handleThreadContextMenu}
51065139
onSettle={attemptSettle}
5107-
onSettleSweepStart={startSettleSweep}
5140+
onActionSweepStart={startActionSweep}
51085141
onUnsettle={attemptUnsettle}
51095142
onSnooze={attemptSnooze}
51105143
onUnsnooze={attemptUnsnooze}

‎docs/user/thread-sidebar.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ runs a command, such as a dev server, stays open.
132132

133133
On web and desktop, press a thread's **Settle** button and drag up or down to
134134
settle every thread in that section between it and the one you release on.
135+
The **Un-settle** and **Wake** buttons work the same way in their sections.
135136
Press `Escape` while dragging to cancel.
136137

137138
By default, environments settle inactive threads after three days and settle

0 commit comments

Comments
 (0)