From 120d684da91b11da8e29dc7a2e3d09a5f330f1ed Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sun, 26 Jul 2026 15:33:34 -0700 Subject: [PATCH] feat(mobile): surface snoozed threads with a shelf and wake action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mobile could snooze a thread but never see it again: snoozedCount only fed the empty state, so snoozed threads were invisible whenever any other thread existed, and nothing anywhere called thread.unsnooze. The swipe Snooze action added earlier in this branch made that a one-way door. Ports the desktop snoozed shelf (SidebarV2, #4311) to both mobile v2 surfaces: - buildThreadListV2Items now returns snoozed rows between the inbox and the settled tail, sorted soonest-wake-first, plus the index where the shelf header belongs. Collapsed by default like web; the open thread keeps its row so a snoozed thread opened in iPad split view can't vanish behind a closed shelf. - Snoozed rows show their wake time ("2h", "3d") in blue instead of last activity, via snoozeWakeLabel ported from web's Sidebar.snooze.ts. - Waking: swipe primary becomes Wake, long-press menu offers "Wake thread", both routed through a new unsnoozeThread action. Snooze is not offered on an already-snoozed row. - Drops the all-snoozed empty states on both surfaces — the shelf header renders whenever anything is snoozed, so the list is never truly empty. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/features/home/HomeRouteScreen.tsx | 11 +- apps/mobile/src/features/home/HomeScreen.tsx | 191 +++++++++++------- .../src/features/home/useThreadListActions.ts | 42 +++- .../threads/ThreadNavigationSidebar.tsx | 94 ++++++--- .../features/threads/thread-list-v2-items.tsx | 107 +++++++++- .../src/features/threads/threadListV2.test.ts | 118 +++++++++++ .../src/features/threads/threadListV2.ts | 95 ++++++++- 7 files changed, 539 insertions(+), 119 deletions(-) diff --git a/apps/mobile/src/features/home/HomeRouteScreen.tsx b/apps/mobile/src/features/home/HomeRouteScreen.tsx index e299f9ab7f..aeb99de243 100644 --- a/apps/mobile/src/features/home/HomeRouteScreen.tsx +++ b/apps/mobile/src/features/home/HomeRouteScreen.tsx @@ -29,8 +29,14 @@ export function HomeRouteScreen() { const { savedConnectionsById } = useSavedRemoteConnections(); const navigation = useNavigation(); const [searchQuery, setSearchQuery] = useState(""); - const { archiveThread, confirmDeleteThread, settleThread, snoozeThread, unsettleThread } = - useThreadListActions(); + const { + archiveThread, + confirmDeleteThread, + settleThread, + snoozeThread, + unsnoozeThread, + unsettleThread, + } = useThreadListActions(); const pendingTasks = usePendingNewTasks(); const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions(); const environments = useMemo( @@ -136,6 +142,7 @@ export function HomeRouteScreen() { onDeleteThread={confirmDeleteThread} onSettleThread={settleThread} onSnoozeThread={snoozeThread} + onUnsnoozeThread={unsnoozeThread} onUnsettleThread={unsettleThread} onEnvironmentChange={setSelectedEnvironmentId} onProjectChange={setSelectedProjectKey} diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx index c247e6b84b..fb389e09d7 100644 --- a/apps/mobile/src/features/home/HomeScreen.tsx +++ b/apps/mobile/src/features/home/HomeScreen.tsx @@ -35,13 +35,14 @@ import { ThreadListRow, ThreadListShowMoreRow, } from "../threads/thread-list-items"; -import { ThreadListV2Row } from "../threads/thread-list-v2-items"; +import { ThreadListV2Row, ThreadListV2SnoozedShelfHeader } from "../threads/thread-list-v2-items"; import { buildThreadListV2Items, THREAD_LIST_V2_SETTLED_INITIAL_COUNT, THREAD_LIST_V2_SETTLED_PAGE_COUNT, type ThreadListV2Item, } from "../threads/threadListV2"; + import type { HomeListFilterMenuEnvironment } from "./home-list-filter-menu"; import { buildHomeListLayout, @@ -64,6 +65,11 @@ import { shouldShowWorkspaceConnectionStatus } from "./workspace-connection-stat /* ─── Types ──────────────────────────────────────────────────────────── */ +/** v2 list rows: thread rows plus the standalone snoozed-shelf header. */ +type ThreadListV2DisplayItem = + | { readonly type: "thread"; readonly item: ThreadListV2Item } + | { readonly type: "snoozed-shelf-header"; readonly count: number }; + interface HomeScreenProps { readonly projects: ReadonlyArray; readonly threads: ReadonlyArray; @@ -93,6 +99,8 @@ interface HomeScreenProps { readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise; /** Snoozes for the swipe action's one-hour default. */ readonly onSnoozeThread: (thread: EnvironmentThreadShell) => Promise; + /** Wakes a snoozed thread from the snoozed shelf. */ + readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => Promise; readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void; readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void; readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void; @@ -459,6 +467,12 @@ export function HomeScreen(props: HomeScreenProps) { }, [props.onSnoozeThread], ); + const handleUnsnoozeThread = useCallback( + (thread: EnvironmentThreadShell) => { + void props.onUnsnoozeThread(thread); + }, + [props.onUnsnoozeThread], + ); const handleDeleteThread = props.onDeleteThread; const handleUnsettleThread = props.onUnsettleThread; // The settled tail renders in pages; expansion resets when the filter @@ -476,6 +490,9 @@ export function HomeScreen(props: HomeScreenProps) { () => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT), [], ); + // Collapsed by default, like web: the shelf is a shelf, not a second inbox. + const [snoozedShelfExpanded, setSnoozedShelfExpanded] = useState(false); + const toggleSnoozedShelf = useCallback(() => setSnoozedShelfExpanded((value) => !value), []); // now is quantized to the minute and ticks so the inactivity auto-settle // boundary is actually crossed while the app stays open (mirrors web); // without a clock dependency the partition memoizes a frozen "now". @@ -516,7 +533,13 @@ export function HomeScreen(props: HomeScreenProps) { }, [serverConfigs]); const threadListV2Layout = useMemo(() => { if (!threadListV2Enabled) - return { items: [], hiddenSettledCount: 0, snoozedCount: 0, nextSnoozeWakeAt: null }; + return { + items: [], + hiddenSettledCount: 0, + snoozedCount: 0, + snoozedShelfHeaderIndex: null, + nextSnoozeWakeAt: null, + }; // Settled threads are live shells; archived threads keep their original // "hidden from lists" meaning. return buildThreadListV2Items({ @@ -530,11 +553,16 @@ export function HomeScreen(props: HomeScreenProps) { settledLimit: settledVisibleCount, now: `${nowMinute}:00.000Z`, snoozeNow: new Date().toISOString(), + snoozedShelfExpanded, + // Phones navigate away on select, so no row is ever "open" here — the + // collapsed-shelf exception is an iPad split-view concern. + selectedThreadKey: null, }); }, [ changeRequestStateByKey, nowMinute, snoozeWakeTick, + snoozedShelfExpanded, settledVisibleCount, settlementEnvironmentIds, snoozeEnvironmentIds, @@ -558,57 +586,93 @@ export function HomeScreen(props: HomeScreenProps) { // unchanged: after a clamped fire (wake beyond the 32-bit setTimeout // range) the boundary string is identical and the chain would die. }, [nextSnoozeWakeAt, snoozeWakeTick]); - const threadListV2Items = threadListV2Layout.items; + // The shelf header is a list row of its own: it must render even when the + // shelf is collapsed and has no rows to hang it on. + const threadListV2Items = useMemo((): ThreadListV2DisplayItem[] => { + const rows: ThreadListV2DisplayItem[] = threadListV2Layout.items.map((item) => ({ + type: "thread" as const, + item, + })); + const headerIndex = threadListV2Layout.snoozedShelfHeaderIndex; + if (headerIndex !== null) { + rows.splice(headerIndex, 0, { + type: "snoozed-shelf-header", + count: threadListV2Layout.snoozedCount, + }); + } + return rows; + }, [ + threadListV2Layout.items, + threadListV2Layout.snoozedCount, + threadListV2Layout.snoozedShelfHeaderIndex, + ]); const renderV2Item = useCallback( - ({ item }: { readonly item: ThreadListV2Item }) => ( - - provider.instanceId === - (item.thread.session?.providerInstanceId ?? item.thread.modelSelection.instanceId), - )?.driver ?? null - } - environmentLabel={ - Object.keys(props.savedConnectionsById).length > 1 - ? (props.savedConnectionsById[item.thread.environmentId]?.environmentLabel ?? null) - : null - } - onSelectThread={props.onSelectThread} - onDeleteThread={handleDeleteThread} - onArchiveThread={props.onArchiveThread} - settlementSupported={settlementEnvironmentIds.has(item.thread.environmentId)} - onSettleThread={handleSettleThread} - snoozeSupported={snoozeEnvironmentIds.has(item.thread.environmentId)} - onSnoozeThread={handleSnoozeThread} - onUnsettleThread={handleUnsettleThread} - onChangeRequestState={handleChangeRequestState} - projectCwd={ - projectCwdByKey.get(scopedProjectKey(item.thread.environmentId, item.thread.projectId)) ?? - null - } - onSwipeableClose={handleSwipeableClose} - onSwipeableWillOpen={handleSwipeableWillOpen} - /> - ), + ({ item: displayItem }: { readonly item: ThreadListV2DisplayItem }) => { + if (displayItem.type === "snoozed-shelf-header") { + return ( + + ); + } + const item = displayItem.item; + return ( + + provider.instanceId === + (item.thread.session?.providerInstanceId ?? + item.thread.modelSelection.instanceId), + )?.driver ?? null + } + environmentLabel={ + Object.keys(props.savedConnectionsById).length > 1 + ? (props.savedConnectionsById[item.thread.environmentId]?.environmentLabel ?? null) + : null + } + onSelectThread={props.onSelectThread} + onDeleteThread={handleDeleteThread} + onArchiveThread={props.onArchiveThread} + settlementSupported={settlementEnvironmentIds.has(item.thread.environmentId)} + onSettleThread={handleSettleThread} + snoozeSupported={snoozeEnvironmentIds.has(item.thread.environmentId)} + onSnoozeThread={handleSnoozeThread} + onUnsnoozeThread={handleUnsnoozeThread} + onUnsettleThread={handleUnsettleThread} + onChangeRequestState={handleChangeRequestState} + projectCwd={ + projectCwdByKey.get( + scopedProjectKey(item.thread.environmentId, item.thread.projectId), + ) ?? null + } + onSwipeableClose={handleSwipeableClose} + onSwipeableWillOpen={handleSwipeableWillOpen} + /> + ); + }, [ handleChangeRequestState, handleDeleteThread, handleSettleThread, handleSnoozeThread, + handleUnsnoozeThread, handleSwipeableClose, handleSwipeableWillOpen, handleUnsettleThread, @@ -620,11 +684,16 @@ export function HomeScreen(props: HomeScreenProps) { serverConfigs, settlementEnvironmentIds, snoozeEnvironmentIds, + snoozedShelfExpanded, + toggleSnoozedShelf, v2ProjectTitleByProjectKey, ], ); const v2KeyExtractor = useCallback( - (item: ThreadListV2Item) => `${item.thread.environmentId}:${item.thread.id}`, + (item: ThreadListV2DisplayItem) => + item.type === "snoozed-shelf-header" + ? "snoozed-shelf-header" + : `${item.item.thread.environmentId}:${item.item.thread.id}`, [], ); @@ -857,31 +926,13 @@ export function HomeScreen(props: HomeScreenProps) { // Self-contained: v1's listEmpty keys off projectGroups, which ignores the // v2 project scope, so it can be null (results elsewhere) while this list // is empty. Search outranks the scope — "No results" names the actionable - // fact when a query is active. Snoozed threads outrank the rest: "No - // threads yet" over an inbox that is merely all-snoozed reads as data - // loss. Pending tasks render in the header, so the list showing them - // isn't empty in the user's eyes. - const v2SnoozedCount = threadListV2Layout.snoozedCount; + // fact when a query is active. Pending tasks render in the header, so the + // list showing them isn't empty in the user's eyes. Snoozed threads need + // no empty-state case: the shelf header renders as a list row whenever + // anything is snoozed, so an all-snoozed list is never actually empty. const v2ListEmpty = v2PendingTasks.length > 0 ? null : hasSearchQuery ? ( - v2SnoozedCount > 0 ? ( - // The snoozed threads already passed this search filter: "No - // results" would claim nothing matched when matches are merely - // parked. - - ) : ( - - ) - ) : v2SnoozedCount > 0 ? ( - + ) : v2ScopedProjectGroup !== null ? ( void; readonly settleThread: (thread: EnvironmentThreadShell) => Promise; readonly snoozeThread: (thread: EnvironmentThreadShell) => Promise; + readonly unsnoozeThread: (thread: EnvironmentThreadShell) => Promise; readonly unsettleThread: (thread: EnvironmentThreadShell) => Promise; } { const executeAction = useThreadActionExecutor(); const snoozeMutation = useAtomCommand(threadEnvironment.snooze, { reportFailure: false }); + const unsnoozeMutation = useAtomCommand(threadEnvironment.unsnooze, { reportFailure: false }); const archiveThread = useCallback( (thread: EnvironmentThreadShell) => { @@ -256,6 +258,37 @@ export function useThreadListActions(): { }, [snoozeMutation], ); + // Waking has no client-side precondition (canSnooze guards the way IN, not + // the way OUT) — a thread the user can see on the shelf can always wake. + const unsnoozeThread = useCallback( + async (thread: EnvironmentThreadShell) => { + if (!environmentSupportsSnooze(thread.environmentId)) { + Alert.alert( + "Could not wake thread", + "This environment's server does not support snoozing yet. Update the server to wake this thread.", + ); + return false; + } + + selectionHaptic(); + const result = await unsnoozeMutation({ + environmentId: thread.environmentId, + input: { threadId: thread.id, reason: "user" }, + }); + if (result._tag === "Failure") { + const error = Cause.squash(result.cause); + Alert.alert( + "Could not wake thread", + error instanceof Error && error.message.trim().length > 0 + ? error.message + : "The thread could not be woken.", + ); + return false; + } + return true; + }, + [unsnoozeMutation], + ); const unsettleThread = useCallback( async (thread: EnvironmentThreadShell) => (await executeAction("unsettle", thread)) === true, [executeAction], @@ -263,7 +296,14 @@ export function useThreadListActions(): { const confirmDeleteThread = useConfirmDeleteThread(executeAction); - return { archiveThread, confirmDeleteThread, settleThread, snoozeThread, unsettleThread }; + return { + archiveThread, + confirmDeleteThread, + settleThread, + snoozeThread, + unsnoozeThread, + unsettleThread, + }; } export function useArchivedThreadListActions( diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx index 3878606ca2..a5e8f62a4a 100644 --- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx +++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx @@ -63,7 +63,7 @@ import { ThreadListRow, ThreadListShowMoreRow, } from "./thread-list-items"; -import { ThreadListV2Row } from "./thread-list-v2-items"; +import { ThreadListV2Row, ThreadListV2SnoozedShelfHeader } from "./thread-list-v2-items"; import { buildThreadListV2Items, THREAD_LIST_V2_SETTLED_INITIAL_COUNT, @@ -83,6 +83,11 @@ type SidebarListItem = readonly isLast: boolean; } | { readonly type: "v2-thread"; readonly key: string; readonly item: ThreadListV2Item } + | { + readonly type: "v2-snoozed-shelf-header"; + readonly key: string; + readonly count: number; + } | { readonly type: "v2-show-more"; readonly key: string; readonly hiddenCount: number }; /** @@ -194,8 +199,14 @@ function ThreadNavigationSidebarPane( const openSwipeableRef = useRef(null); const headerIsOverContentRef = useRef(false); const sidebarScrollGesture = useMemo(() => Gesture.Native(), []); - const { archiveThread, confirmDeleteThread, settleThread, snoozeThread, unsettleThread } = - useThreadListActions(); + const { + archiveThread, + confirmDeleteThread, + settleThread, + snoozeThread, + unsnoozeThread, + unsettleThread, + } = useThreadListActions(); const preferencesResult = useAtomValue(mobilePreferencesAtom); const threadListV2Enabled = AsyncResult.isSuccess(preferencesResult) && @@ -395,6 +406,9 @@ function ThreadNavigationSidebarPane( () => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT), [], ); + // Collapsed by default, like web: the shelf is a shelf, not a second inbox. + const [snoozedShelfExpanded, setSnoozedShelfExpanded] = useState(false); + const toggleSnoozedShelf = useCallback(() => setSnoozedShelfExpanded((value) => !value), []); // now ticks per minute so the inactivity auto-settle boundary is actually // crossed while the pane stays open; without a clock dependency the // partition memoizes a frozen "now". @@ -435,7 +449,13 @@ function ThreadNavigationSidebarPane( }, [serverConfigs]); const threadListV2Layout = useMemo(() => { if (!threadListV2Enabled) - return { items: [], hiddenSettledCount: 0, snoozedCount: 0, nextSnoozeWakeAt: null }; + return { + items: [], + hiddenSettledCount: 0, + snoozedCount: 0, + snoozedShelfHeaderIndex: null, + nextSnoozeWakeAt: null, + }; return buildThreadListV2Items({ threads: threads.filter((thread) => thread.archivedAt === null), environmentId: options.selectedEnvironmentId, @@ -447,11 +467,17 @@ function ThreadNavigationSidebarPane( settledLimit: settledVisibleCount, now: `${nowMinute}:00.000Z`, snoozeNow: new Date().toISOString(), + snoozedShelfExpanded, + // Split view keeps a thread open beside the list: a snoozed one must + // keep its row (and its Wake action) even while the shelf is closed. + selectedThreadKey: props.selectedThreadKey ?? null, }); }, [ changeRequestStateByKey, nowMinute, snoozeWakeTick, + snoozedShelfExpanded, + props.selectedThreadKey, options.selectedEnvironmentId, props.searchQuery, settledVisibleCount, @@ -500,13 +526,22 @@ function ThreadNavigationSidebarPane( pendingTask, isLast: index === v2PendingTasks.length - 1, })); - for (const item of threadListV2Layout.items) { - items.push({ - type: "v2-thread" as const, - key: scopedThreadKey(item.thread.environmentId, item.thread.id), - item, + const threadRows: SidebarListItem[] = threadListV2Layout.items.map((item) => ({ + type: "v2-thread" as const, + key: scopedThreadKey(item.thread.environmentId, item.thread.id), + item, + })); + // The shelf header is a row of its own: collapsed, it IS the shelf, so + // it has no thread row to hang off. splice() handles the all-snoozed + // case (index lands at the end) without a separate branch. + if (threadListV2Layout.snoozedShelfHeaderIndex !== null) { + threadRows.splice(threadListV2Layout.snoozedShelfHeaderIndex, 0, { + type: "v2-snoozed-shelf-header", + key: "v2-snoozed-shelf-header", + count: threadListV2Layout.snoozedCount, }); } + items.push(...threadRows); if (threadListV2Layout.hiddenSettledCount > 0) { items.push({ type: "v2-show-more", @@ -715,6 +750,9 @@ function ThreadNavigationSidebarPane( if (previous.type === "v2-show-more" && item.type === "v2-show-more") { return previous.hiddenCount === item.hiddenCount; } + if (previous.type === "v2-snoozed-shelf-header" && item.type === "v2-snoozed-shelf-header") { + return previous.count === item.count; + } if (previous.type === "v2-pending-task" && item.type === "v2-pending-task") { return previous.pendingTask === item.pendingTask && previous.isLast === item.isLast; } @@ -722,9 +760,11 @@ function ThreadNavigationSidebarPane( previous.type === "v2-thread" || previous.type === "v2-show-more" || previous.type === "v2-pending-task" || + previous.type === "v2-snoozed-shelf-header" || item.type === "v2-thread" || item.type === "v2-show-more" || - item.type === "v2-pending-task" + item.type === "v2-pending-task" || + item.type === "v2-snoozed-shelf-header" ) { return false; } @@ -774,6 +814,7 @@ function ThreadNavigationSidebarPane( thread={thread} variant={item.item.variant} showSettledDivider={item.item.showSettledDivider} + snoozed={item.item.snoozed} project={projectByKey.get(scopeKey) ?? null} projectTitle={projectTitleByProjectKey.get(scopeKey)} providerDriver={ @@ -802,6 +843,7 @@ function ThreadNavigationSidebarPane( onSettleThread={settleThread} snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)} onSnoozeThread={snoozeThread} + onUnsnoozeThread={unsnoozeThread} onUnsettleThread={unsettleThread} onChangeRequestState={handleChangeRequestState} projectCwd={projectCwdByKey.get(scopeKey) ?? null} @@ -811,6 +853,15 @@ function ThreadNavigationSidebarPane( /> ); } + case "v2-snoozed-shelf-header": + return ( + + ); case "v2-show-more": return ( {catalogState.isLoadingConnections ? "Loading threads…" : props.searchQuery.trim().length > 0 - ? snoozedCount > 0 - ? // Snoozed matches passed this same search filter — "No - // matching threads" would misreport them as nonexistent. - snoozedCount === 1 - ? "1 matching thread snoozed" - : "All matching threads snoozed" - : "No matching threads" - : snoozedCount > 0 - ? snoozedCount === 1 - ? "1 thread snoozed" - : `${snoozedCount} threads snoozed` - : selectedProjectScope !== null - ? `No threads in ${selectedProjectScope.title}` - : "No threads yet"} + ? "No matching threads" + : selectedProjectScope !== null + ? `No threads in ${selectedProjectScope.title}` + : "No threads yet"} ); diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsx index 99dbe5b38b..b3d3528621 100644 --- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx +++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx @@ -5,9 +5,10 @@ import type { import { canSnooze } from "@t3tools/client-runtime/state/thread-settled"; import type { MenuAction } from "@react-native-menu/menu"; import { memo, useCallback, useEffect, useMemo, useState, type ComponentProps } from "react"; -import { Platform, Pressable, useWindowDimensions, View } from "react-native"; +import { Platform, Pressable, useColorScheme, useWindowDimensions, View } from "react-native"; import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable"; +import { SymbolView } from "../../components/AppSymbol"; import { AppText as Text } from "../../components/AppText"; import { ControlPillMenu } from "../../components/ControlPill"; import { ProjectFavicon } from "../../components/ProjectFavicon"; @@ -21,6 +22,7 @@ import { resolveThreadListV2SnoozeGateExpiryMs, resolveThreadListV2Status, resolveThreadListV2SwipeActions, + snoozeWakeLabel, type ThreadListV2Status, } from "./threadListV2"; @@ -65,6 +67,12 @@ const SLIM_MENU_ACTIONS: MenuAction[] = [ { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } }, ]; +// Snoozed rows wake instead of settling — the thread is parked, not done. +const SNOOZED_MENU_ACTIONS: MenuAction[] = [ + { id: "unsnooze", title: "Wake thread", image: "clock" }, + { id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } }, +]; + // Pre-settlement servers: no lifecycle items, archive fills the gap. const LEGACY_MENU_ACTIONS: MenuAction[] = [ { id: "archive", title: "Archive", image: "archivebox" }, @@ -91,10 +99,58 @@ export const ThreadListV2SettledDivider = memo(function ThreadListV2SettledDivid ); }); +// SymbolView takes a literal tint, so the shelf chevron can't ride the +// blue-600/blue-400 Tailwind pair the label uses. Same values, resolved here. +const SNOOZE_ACCENT_LIGHT = "#2563eb"; +const SNOOZE_ACCENT_DARK = "#60a5fa"; + +/** + * Snoozed shelf header: tappable, showing the count while collapsed so the + * shelf's whole footprint is one line. Mirrors web's snoozed shelf toggle — + * parked work stays reachable without competing with the inbox. + */ +export const ThreadListV2SnoozedShelfHeader = memo(function ThreadListV2SnoozedShelfHeader(props: { + readonly count: number; + readonly expanded: boolean; + readonly onToggle: () => void; + readonly pane?: "screen" | "sidebar"; +}) { + const colorScheme = useColorScheme(); + return ( + ({ opacity: pressed ? 0.6 : 1 })} + > + + {props.expanded ? "Snoozed" : `Snoozed (${props.count})`} + + + + + ); +}); + export const ThreadListV2Row = memo(function ThreadListV2Row(props: { readonly thread: EnvironmentThreadShell; readonly variant: "card" | "slim"; readonly showSettledDivider: boolean; + /** Snoozed-shelf row: shows its wake time and offers Wake, not Settle. */ + readonly snoozed?: boolean; readonly project: EnvironmentProject | null; readonly projectTitle?: string; readonly providerDriver: string | null; @@ -118,6 +174,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { readonly onDeleteThread: (thread: EnvironmentThreadShell) => void; readonly onSettleThread: (thread: EnvironmentThreadShell) => void; readonly onSnoozeThread: (thread: EnvironmentThreadShell) => void; + readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => void; readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void; readonly onArchiveThread: (thread: EnvironmentThreadShell) => void; /** False on environments whose server predates thread.settle/unsettle: @@ -146,10 +203,12 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { onDeleteThread, onSettleThread, onSnoozeThread, + onUnsnoozeThread, onUnsettleThread, onArchiveThread, onChangeRequestState, } = props; + const snoozedRow = props.snoozed === true; const pr = useThreadPr(thread, props.projectCwd ?? props.project?.workspaceRoot ?? null); const prState = pr?.state ?? null; @@ -172,16 +231,18 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]); const handleSettle = useCallback(() => onSettleThread(thread), [onSettleThread, thread]); const handleSnooze = useCallback(() => onSnoozeThread(thread), [onSnoozeThread, thread]); + const handleUnsnooze = useCallback(() => onUnsnoozeThread(thread), [onUnsnoozeThread, thread]); const handleUnsettle = useCallback(() => onUnsettleThread(thread), [onUnsettleThread, thread]); const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]); const handleMenuAction = useCallback( ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => { if (nativeEvent.event === "settle") handleSettle(); if (nativeEvent.event === "unsettle") handleUnsettle(); + if (nativeEvent.event === "unsnooze") handleUnsnooze(); if (nativeEvent.event === "archive") handleArchive(); if (nativeEvent.event === "delete") handleDelete(); }, - [handleArchive, handleDelete, handleSettle, handleUnsettle], + [handleArchive, handleDelete, handleSettle, handleUnsettle, handleUnsnooze], ); // Swipe: the v2 primary action is the lifecycle transition. Every settled @@ -209,6 +270,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { settlementSupported: props.settlementSupported, snoozeSupported: props.snoozeSupported, snoozable: canSnooze(thread, { now: new Date().toISOString() }), + snoozed: snoozedRow, }); const primaryAction = useMemo(() => { // Pre-settlement server: archive is the swipe action, as in v1. (Slim @@ -222,6 +284,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { onPress: handleArchive, }; } + if (swipeActions.primary === "unsnooze") { + return { + accessibilityLabel: `Wake ${thread.title} now`, + icon: "clock" as const, + label: "Wake", + onPress: handleUnsnooze, + }; + } return swipeActions.primary === "unsettle" ? { accessibilityLabel: `Un-settle ${thread.title}`, @@ -235,7 +305,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { label: "Settle", onPress: handleSettle, }; - }, [handleArchive, handleSettle, handleUnsettle, swipeActions.primary, thread.title]); + }, [ + handleArchive, + handleSettle, + handleUnsettle, + handleUnsnooze, + swipeActions.primary, + thread.title, + ]); const secondaryAction = useMemo( () => swipeActions.secondary === "snooze" @@ -450,14 +527,22 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { > {thread.title} + {/* Snoozed rows show when they come BACK, not when they were last + touched — the return ticket is the row's whole story. */} - {relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt)} + {snoozedRow && thread.snoozedUntil != null + ? snoozeWakeLabel(thread.snoozedUntil, new Date()) + : relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt)} @@ -489,11 +574,13 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { {(close) => ( { }), ).toEqual({ primary: "archive", secondary: null }); }); + + it("offers wake and no snooze on a snoozed row", () => { + expect( + resolveThreadListV2SwipeActions({ + variant: "slim", + settlementSupported: true, + snoozeSupported: true, + snoozable: true, + snoozed: true, + }), + ).toEqual({ primary: "unsnooze", secondary: null }); + }); +}); + +describe("snoozeWakeLabel", () => { + const now = new Date("2026-06-02T00:00:00.000Z"); + + it("formats remaining time coarsely, rounding up", () => { + expect(snoozeWakeLabel("2026-06-02T00:30:00.000Z", now)).toBe("30m"); + expect(snoozeWakeLabel("2026-06-02T01:30:00.000Z", now)).toBe("2h"); + expect(snoozeWakeLabel("2026-06-03T02:00:00.000Z", now)).toBe("2d"); + }); + + it("never reads zero or negative while still snoozed", () => { + expect(snoozeWakeLabel("2026-06-02T00:00:30.000Z", now)).toBe("1m"); + expect(snoozeWakeLabel("2026-06-01T23:59:59.000Z", now)).toBe("now"); + expect(snoozeWakeLabel("not-a-date", now)).toBe("now"); + }); }); describe("resolveThreadListV2SnoozeGateExpiryMs", () => { @@ -220,6 +249,95 @@ describe("buildThreadListV2Items", () => { expect(layout.nextSnoozeWakeAt).toBe("2026-06-02T09:00:00.000Z"); }); + it("builds snoozed rows between active and settled when the shelf is expanded", () => { + const layout = buildThreadListV2Items({ + threads: [ + makeThread({ id: ThreadId.make("active"), title: "Active" }), + makeThread({ + id: ThreadId.make("settled"), + title: "Settled", + settledOverride: "settled", + }), + makeThread({ + id: ThreadId.make("later"), + title: "Wakes later", + snoozedUntil: "2026-06-03T09:00:00.000Z", + snoozedAt: "2026-06-01T12:00:00.000Z", + }), + makeThread({ + id: ThreadId.make("sooner"), + title: "Wakes sooner", + snoozedUntil: "2026-06-02T09:00:00.000Z", + snoozedAt: "2026-06-01T12:00:00.000Z", + }), + ], + environmentId: null, + searchQuery: "", + now: NOW, + snoozedShelfExpanded: true, + }); + + // Soonest wake first, and the shelf sits between inbox and settled. + expect(layout.items.map((item) => item.thread.id)).toEqual([ + "active", + "sooner", + "later", + "settled", + ]); + expect(layout.items.map((item) => item.snoozed)).toEqual([false, true, true, false]); + expect(layout.snoozedShelfHeaderIndex).toBe(1); + expect(layout.snoozedCount).toBe(2); + }); + + it("collapses to a header-only shelf, reporting the index past the last row", () => { + const layout = buildThreadListV2Items({ + threads: [ + makeThread({ + id: ThreadId.make("snoozed"), + title: "Snoozed", + snoozedUntil: "2026-06-03T09:00:00.000Z", + snoozedAt: "2026-06-01T12:00:00.000Z", + }), + ], + environmentId: null, + searchQuery: "", + now: NOW, + }); + + expect(layout.items).toEqual([]); + expect(layout.snoozedCount).toBe(1); + // Header still renders — the count IS the shelf while collapsed. + expect(layout.snoozedShelfHeaderIndex).toBe(0); + }); + + it("keeps the open thread on a collapsed shelf so it never vanishes", () => { + const layout = buildThreadListV2Items({ + threads: [ + makeThread({ + id: ThreadId.make("open"), + title: "Open", + snoozedUntil: "2026-06-03T09:00:00.000Z", + snoozedAt: "2026-06-01T12:00:00.000Z", + }), + makeThread({ + id: ThreadId.make("other"), + title: "Other", + snoozedUntil: "2026-06-03T09:00:00.000Z", + snoozedAt: "2026-06-01T12:00:00.000Z", + }), + ], + environmentId: null, + searchQuery: "", + now: NOW, + selectedThreadKey: `${environmentId}:open`, + }); + + expect(layout.items.map((item) => item.thread.id)).toEqual(["open"]); + expect(layout.items[0]?.snoozed).toBe(true); + // Both still count: the shelf header reports everything parked. + expect(layout.snoozedCount).toBe(2); + }); + it("keeps snoozed threads visible on environments without the snooze capability", () => { const layout = buildThreadListV2Items({ threads: [ diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.ts index fe1683e845..483b0e9db0 100644 --- a/apps/mobile/src/features/threads/threadListV2.ts +++ b/apps/mobile/src/features/threads/threadListV2.ts @@ -16,17 +16,24 @@ import type { EnvironmentId, ProjectId } from "@t3tools/contracts"; * unlabeled resting state. */ export type ThreadListV2Status = "approval" | "input" | "working" | "failed" | "ready"; -export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze"; +export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze"; export function resolveThreadListV2SwipeActions(input: { readonly variant: "card" | "slim"; readonly settlementSupported: boolean; readonly snoozeSupported: boolean; readonly snoozable: boolean; + /** Row is on the snoozed shelf. */ + readonly snoozed?: boolean; }): { readonly primary: Exclude; readonly secondary: "snooze" | null; } { + // A snoozed row's one lifecycle move is waking: settling parked work is + // meaningless, and re-snoozing an already-snoozed thread is a no-op. + if (input.snoozed === true) { + return { primary: "unsnooze", secondary: null }; + } const primary = input.settlementSupported ? input.variant === "slim" ? "unsettle" @@ -38,6 +45,25 @@ export function resolveThreadListV2SwipeActions(input: { }; } +const HOUR_MS = 60 * 60 * 1_000; +const DAY_MS = 24 * HOUR_MS; + +/** + * Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes + * round up so a snooze never reads "0m" while still hidden. Ported from + * web's snoozeWakeLabel (apps/web/src/components/Sidebar.snooze.ts) so both + * platforms describe a wake time identically. + */ +export function snoozeWakeLabel(snoozedUntil: string, now: Date): string { + const wakeMs = Date.parse(snoozedUntil); + if (Number.isNaN(wakeMs)) return "now"; + const remainingMs = wakeMs - now.getTime(); + if (remainingMs <= 0) return "now"; + if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`; + if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`; + return `${Math.ceil(remainingMs / DAY_MS)}d`; +} + /** * When a thread's snooze eligibility can flip on its own, as epoch ms — the * moment the queued-turn-start grace window expires and `canSnooze` starts @@ -128,6 +154,9 @@ export interface ThreadListV2Item { readonly variant: "card" | "slim"; /** First settled row after the card block draws the SETTLED divider. */ readonly showSettledDivider: boolean; + /** Snoozed-shelf row: renders its wake time instead of its last-activity + time, and offers Wake instead of Settle. */ + readonly snoozed: boolean; readonly isLast: boolean; } @@ -135,11 +164,17 @@ export interface ThreadListV2Layout { readonly items: ThreadListV2Item[]; /** Settled threads beyond the render limit (behind "Show more"). */ readonly hiddenSettledCount: number; - /** Snoozed threads hidden from the list (visibility parity with web's - collapsed Snoozed shelf; mobile has no shelf UI yet). */ + /** Snoozed threads matching the current filters. Drives the shelf header, + which shows the count while collapsed; rows only build when the shelf + is expanded (or for the open thread). */ readonly snoozedCount: number; - /** Soonest wake time among hidden snoozed threads, or null. Callers arm - a timeout at this boundary so the list re-partitions the moment a + /** Index in `items` where the snoozed shelf header belongs, or null when + nothing is snoozed. Callers splice their own header element in here: + the header must render even while the shelf is collapsed (its count is + the whole shelf then), so it can't hang off a row flag. */ + readonly snoozedShelfHeaderIndex: number | null; + /** Soonest wake time among snoozed threads, or null. Callers arm a + timeout at this boundary so the list re-partitions the moment a snooze expires instead of on the next minute tick. */ readonly nextSnoozeWakeAt: string | null; } @@ -177,6 +212,13 @@ export function buildThreadListV2Items(input: { second-precise, so classifying with the floored minute would hold a woken thread hidden for up to a minute. Defaults to `now`. */ readonly snoozeNow?: string; + /** Expands the snoozed shelf into rows. Collapsed (the default, matching + web) the shelf is just its header + count. */ + readonly snoozedShelfExpanded?: boolean; + /** Scoped key ("environmentId:threadId") of the open thread. A snoozed + thread reached by route keeps its row even while the shelf is + collapsed — the open thread must never vanish behind a shelf. */ + readonly selectedThreadKey?: string | null; }): ThreadListV2Layout { const now = input.now ?? new Date().toISOString(); const snoozeNow = input.snoozeNow ?? now; @@ -188,7 +230,7 @@ export function buildThreadListV2Items(input: { const active: EnvironmentThreadShell[] = []; const settled: EnvironmentThreadShell[] = []; - let snoozedCount = 0; + const snoozed: EnvironmentThreadShell[] = []; let nextSnoozeWakeAt: string | null = null; for (const thread of input.threads) { // Callers pass live (unarchived) shells; settled threads are among them @@ -206,7 +248,7 @@ export function buildThreadListV2Items(input: { // wakes (or raises its hand — effectiveSnoozed refuses blocked/failed // work). Snooze outranks settled classification, same as web. if (supportsSnooze && effectiveSnoozed(thread, { now: snoozeNow })) { - snoozedCount += 1; + snoozed.push(thread); if ( thread.snoozedUntil != null && (nextSnoozeWakeAt === null || @@ -227,6 +269,21 @@ export function buildThreadListV2Items(input: { } const orderedActive = sortThreadsForListV2(active); + // Soonest wake first: the shelf reads as a queue of what comes back next. + const orderedSnoozed = [...snoozed].sort( + (left, right) => + parseTimestampMs(left.snoozedUntil ?? "") - parseTimestampMs(right.snoozedUntil ?? ""), + ); + const selectedThreadKey = input.selectedThreadKey ?? null; + const visibleSnoozed = + input.snoozedShelfExpanded === true + ? orderedSnoozed + : // Collapsed: only the open thread survives, so a snoozed thread + // opened by deep link (or snoozed from another device while open) + // keeps its row and its Wake affordance. + orderedSnoozed.filter( + (thread) => `${thread.environmentId}:${thread.id}` === selectedThreadKey, + ); const orderedSettled = [...settled].sort( (left, right) => firstValidTimestampMs(right.latestUserMessageAt, right.updatedAt) - @@ -238,13 +295,32 @@ export function buildThreadListV2Items(input: { const items: ThreadListV2Item[] = []; for (const thread of orderedActive) { - items.push({ thread, variant: "card", showSettledDivider: false, isLast: false }); + items.push({ + thread, + variant: "card", + showSettledDivider: false, + snoozed: false, + isLast: false, + }); + } + // Snoozed shelf sits between the inbox and Settled — out of the way, + // never gone. Slim like settled rows: parked work, not inbox work. + const snoozedShelfHeaderIndex = orderedSnoozed.length > 0 ? items.length : null; + for (const thread of visibleSnoozed) { + items.push({ + thread, + variant: "slim", + showSettledDivider: false, + snoozed: true, + isLast: false, + }); } for (const [index, thread] of visibleSettled.entries()) { items.push({ thread, variant: "slim", showSettledDivider: index === 0, + snoozed: false, isLast: false, }); } @@ -255,7 +331,8 @@ export function buildThreadListV2Items(input: { return { items, hiddenSettledCount: orderedSettled.length - visibleSettled.length, - snoozedCount, + snoozedCount: orderedSnoozed.length, + snoozedShelfHeaderIndex, nextSnoozeWakeAt, }; }