feat(mobile): Bring Thread Menus to Desktop Parity #5962
Closedanirudhsama(GitHub profile, opens in a new tab)wants to merge 16 commits into
main fromrefs/pull/5962/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
anirudhsama(GitHub profile, opens in a new tab) changed the title
- apps/mobile/src/features/threads/thread-read-state.ts line 37OutdatedResolvedby anirudhsama(GitHub profile, opens in a new tab)@@ -0,0 +17,21 @@17+ threadKey: string,18+ visitedAt: string | null | undefined,19+): ThreadLastVisitedAtById {20+ if (!visitedAt) return current;21+ const visitedAtMs = Date.parse(visitedAt);22+ if (!Number.isFinite(visitedAtMs)) return current;23+ const previousVisitedAt = current[threadKey];24+ const previousVisitedAtMs = previousVisitedAt ? Date.parse(previousVisitedAt) : NaN;25+ if (Number.isFinite(previousVisitedAtMs) && previousVisitedAtMs >= visitedAtMs) return current;26+ return { ...current, [threadKey]: visitedAt };27+}28+29+export function setThreadUnreadAt(30+ current: ThreadLastVisitedAtById,31+ threadKey: string,32+ latestTurnCompletedAt: string | null | undefined,33+): ThreadLastVisitedAtById {34+ if (!latestTurnCompletedAt) return current;35+ const completedAtMs = Date.parse(latestTurnCompletedAt);36+ if (Number.isNaN(completedAtMs)) return current;37+ const unreadVisitedAt = new Date(completedAtMs - 1).toISOString();apps/mobile/src/features/threads/thread-list-v2-items.tsx line 617Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -534,3 +579,6 @@534579 if (nativeEvent.event === "move-pin-up") handleMovePinnedUp();535580 if (nativeEvent.event === "move-pin-down") handleMovePinnedDown();536581 if (nativeEvent.event === "archive") handleArchive();582+ if (nativeEvent.event === "rename") handleRename();583+ if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();584+ if (nativeEvent.event === "mark-unread") markThreadUnread();apps/mobile/src/features/threads/ThreadDetailScreen.tsx line 235OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -226,3 +232,4 @@226232 const isSplitLayout = layoutVariant === "split";227233 const contentMaxWidth = isSplitLayout ? CHAT_CONTENT_MAX_WIDTH : undefined;228234 const selectedInstanceId = props.selectedThread.modelSelection.instanceId;235+ useEffect(() => {
anirudhsama(GitHub profile, opens in a new tab) changed the title
- apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx line 479OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -451,3 +452,17 @@451452 },452453 [navigation],453454 );455+ const handleNewThreadFromThread = useCallback(456+ (thread: EnvironmentThreadShell) => {457+ seedNewTaskDraftFromThread(thread);458+ navigation.navigate("NewTaskSheet", {459+ screen: "NewTaskDraft",460+ params: {461+ environmentId: String(thread.environmentId),462+ projectId: String(thread.projectId),463+ title: "New task",464+ },465+ });466+ },467+ [navigation],468+ );
- apps/mobile/src/components/ControlPill.tsx line 130OutdatedResolvedby anirudhsama(GitHub profile, opens in a new tab)@@ -118,3 +120,11 @@118120 },119121 ) {120122 const isDarkMode = useColorScheme() === "dark";123+ const actions = useMemo(124+ () =>125+ Platform.OS === "ios"126+ ? applyDefaultMenuImageColors(props.actions, {127+ // @react-native-menu/menu's Fabric spec requires Int32 colors;128+ // semantic PlatformColor objects prevent the native menu from129+ // being created at all.130+ default: isDarkMode ? "#ffffff" : "#000000",
- apps/mobile/src/features/threads/thread-list-items.tsx line 523OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -487,0 +503,21 @@503+ if (path === null) {504+ Alert.alert("Could not copy path", "This thread does not have a workspace path.");505+ return;506+ }507+ copyTextWithHaptic(path, { target: "thread path", feedback: "selection" });508+ }, [props.projectCwd, thread.worktreePath]);509+ const handleCopyBranch = useCallback(() => {510+ if (thread.branch === null) return;511+ copyTextWithHaptic(thread.branch, { target: "thread branch", feedback: "selection" });512+ }, [thread.branch]);513+ const handleCopyThreadId = useCallback(() => {514+ copyTextWithHaptic(thread.id, { target: "thread ID", feedback: "selection" });515+ }, [thread.id]);516+ const menuActions = useMemo(517+ () =>518+ buildThreadListMenuActions({519+ thread,520+ lifecycleActions: [{ id: "archive", title: "Archive thread", image: "archivebox" }],521+ titleRegenerationSupported: props.titleRegenerationSupported,522+ // Archive is this row's lifecycle action already.523+ showArchiveAction: false,apps/mobile/src/features/threads/thread-list-menu.ts line 70Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +47,21 @@47+ ]48+ : []),49+ { id: "mark-unread", title: "Mark unread", image: "envelope.badge" },50+ ],51+ },52+ {53+ id: "copy",54+ title: "Copy",55+ image: "doc.on.doc",56+ subactions: [57+ { id: "copy-path", title: "Path", image: "folder" },58+ ...(input.thread.branch59+ ? [60+ {61+ id: "copy-branch",62+ title: "Branch",63+ image: "arrow.triangle.branch",64+ } satisfies MenuAction,65+ ]66+ : []),67+ { id: "copy-thread-id", title: "Thread ID", image: "number" },
- apps/mobile/src/features/threads/thread-list-menu.ts line 35Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +18,21 @@18+ session.status === "running" && activeTurnId != null. */19+ readonly isRunning?: boolean;20+}): MenuAction[] {21+ const regeneratingTitle = input.thread.titleRegeneration != null;22+ return [23+ ...(input.thread.branch24+ ? [25+ {26+ id: "new-thread-on-branch",27+ title: `New thread on ${input.thread.branch}`,28+ image: "plus",29+ } satisfies MenuAction,30+ ]31+ : []),32+ // Archive rejects a thread with an active turn; rows that surface it as33+ // their lifecycle action get the same disabled treatment as the tail.34+ ...input.lifecycleActions.map((action) =>35+ action.id === "archive" && input.isRunning === true36+ ? { ...action, attributes: { ...action.attributes, disabled: true } }37+ : action,38+ ),
- apps/mobile/src/features/threads/thread-list-v2-items.tsx line 593Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -561,10 +562,12 @@561- ],562- [pinMenuItem, thread.pinnedAt, titleRegenerationMenuItems],562+ () => [...pinMenuItem, CARD_MENU_ACTIONS[0]!],563+ [pinMenuItem],563564 );564- const snoozedMenuActions = useMemo<MenuAction[]>(565- () => [SNOOZED_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, SNOOZED_MENU_ACTIONS[1]!],566- [titleRegenerationMenuItems],567- );568- const legacyMenuActions = useMemo<MenuAction[]>(569- () => [LEGACY_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, LEGACY_MENU_ACTIONS[1]!],570- [titleRegenerationMenuItems],565+ const lifecycleMenuActions = snoozedRow566+ ? SNOOZED_MENU_ACTIONS567+ : !props.settlementSupported568+ ? LEGACY_MENU_ACTIONS569+ : canUnsettle570+ ? SLIM_MENU_ACTIONS571+ : swipeActions.secondary === "snooze"572+ ? snoozableCardMenuActions573+ : cardMenuActions;apps/mobile/src/components/android-menu-sections.ts line 27Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +4,21 @@4+ readonly action: MenuAction;5+ readonly dividerBefore: boolean;6+}7+8+export function flattenInlineMenuSections(actions: readonly MenuAction[]): AndroidMenuEntry[] {9+ const entries: AndroidMenuEntry[] = [];10+ for (const action of actions) {11+ if (action.attributes?.hidden === true) continue;12+ if (action.displayInline === true && action.subactions) {13+ const visibleChildren = action.subactions.filter(14+ (child) => child.attributes?.hidden !== true,15+ );16+ for (const [index, child] of visibleChildren.entries()) {17+ entries.push({ action: child, dividerBefore: index === 0 && entries.length > 0 });18+ }19+ continue;20+ }21+ entries.push({ action, dividerBefore: false });22+ }23+ return entries;24+}
- apps/mobile/src/features/threads/ThreadDetailScreen.tsx line 667Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -446,3 +453,8 @@446453 const isSplitLayout = layoutVariant === "split";447454 const contentMaxWidth = isSplitLayout ? CHAT_CONTENT_MAX_WIDTH : undefined;448455 const selectedInstanceId = props.selectedThread.modelSelection.instanceId;456+ useFocusEffect(457+ useCallback(() => {458+ markThreadVisited();459+ }, [markThreadVisited]),460+ );
- apps/mobile/src/features/threads/thread-list-v2-items.tsx lines 586 to 586OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -572,4 +570,17 @@572- );573- const legacyMenuActions = useMemo<MenuAction[]>(574- () => [LEGACY_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, LEGACY_MENU_ACTIONS[1]!],575- [titleRegenerationMenuItems],570+ const lifecycleMenuActions = snoozedRow571+ ? SNOOZED_MENU_ACTIONS572+ : !props.settlementSupported573+ ? LEGACY_MENU_ACTIONS574+ : canUnsettle575+ ? SLIM_MENU_ACTIONS576+ : swipeActions.secondary === "snooze"577+ ? snoozableCardMenuActions578+ : cardMenuActions;579+ const menuActions = useMemo(580+ () =>581+ buildThreadListMenuActions({582+ thread,583+ lifecycleActions: lifecycleMenuActions,584+ titleRegenerationSupported: props.titleRegenerationSupported,585+ // Legacy rows already carry Archive as their lifecycle fallback.586+ showArchiveAction: props.settlementSupported,apps/mobile/src/features/threads/thread-list-v2-items.tsx lines 571 to 571OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -559,17 +567,5 @@559- );560- const slimMenuActions = useMemo<MenuAction[]>(561- () => [562- SLIM_MENU_ACTIONS[0]!,563- ...(thread.pinnedAt != null ? pinMenuItem : []),564- ...titleRegenerationMenuItems,565- SLIM_MENU_ACTIONS[1]!,566- ],567- [pinMenuItem, thread.pinnedAt, titleRegenerationMenuItems],567+ () => [...pinMenuItem, CARD_MENU_ACTIONS[0]!],568+ [pinMenuItem],568569 );569- const snoozedMenuActions = useMemo<MenuAction[]>(570- () => [SNOOZED_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, SNOOZED_MENU_ACTIONS[1]!],571- [titleRegenerationMenuItems],572- );573- const legacyMenuActions = useMemo<MenuAction[]>(574- () => [LEGACY_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, LEGACY_MENU_ACTIONS[1]!],575- [titleRegenerationMenuItems],570+ const lifecycleMenuActions = snoozedRow571+ ? SNOOZED_MENU_ACTIONSapps/mobile/src/features/threads/thread-read-state.ts lines 4 to 7OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,7 @@1+export type ThreadLastVisitedAtById = Readonly<Record<string, string>>;2+3+export function hasUnseenThreadCompletion(4+ thread: { readonly latestTurn?: { readonly completedAt?: string | null } | null },5+ lastVisitedAt: string | undefined,6+): boolean {7+ if (!thread.latestTurn?.completedAt || lastVisitedAt === undefined) return false;
- apps/mobile/src/components/android-menu-sections.ts lines 9 to 21OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,21 @@1+import type { MenuAction } from "@react-native-menu/menu";2+3+export interface AndroidMenuEntry {4+ readonly action: MenuAction;5+ readonly dividerBefore: boolean;6+}7+8+export function flattenInlineMenuSections(actions: readonly MenuAction[]): AndroidMenuEntry[] {9+ const entries: AndroidMenuEntry[] = [];10+ for (const action of actions) {11+ if (action.attributes?.hidden === true) continue;12+ if (action.displayInline === true && action.subactions) {13+ const visibleChildren = action.subactions.filter(14+ (child) => child.attributes?.hidden !== true,15+ );16+ for (const [index, child] of visibleChildren.entries()) {17+ entries.push({ action: child, dividerBefore: index === 0 && entries.length > 0 });18+ }19+ continue;20+ }21+ entries.push({ action, dividerBefore: false });
- apps/mobile/src/features/threads/use-thread-read-state.ts line 39OutdatedResolvedby anirudhsama(GitHub profile, opens in a new tab)@@ -0,0 +19,21 @@19+ const preferences = appAtomRegistry.get(mobilePreferencesAtom);20+ return AsyncResult.isSuccess(preferences)21+ ? (preferences.value.threadLastVisitedAtById ?? {})22+ : null;23+}24+25+export function useThreadReadState(26+ thread: Pick<EnvironmentThreadShell, "environmentId" | "id" | "latestTurn">,27+) {28+ const threadKey = scopedThreadKey(thread.environmentId, thread.id);29+ const visitedMarker = useAtomValue(mobileThreadLastVisitedAtAtom(threadKey));30+ const savePreferences = useAtomSet(updateMobilePreferencesAtom);31+ const preferencesReady = visitedMarker !== null;32+ const lastVisitedAt = typeof visitedMarker === "string" ? visitedMarker : undefined;33+34+ const markThreadUnread = useCallback(() => {35+ const current = currentVisitedAtById();36+ if (!preferencesReady || current === null) return;37+ const unreadAt = resolveThreadUnreadAt(thread.latestTurn?.completedAt);38+ if (unreadAt !== undefined && unreadAt !== current[threadKey]) {39+ savePreferences({ threadLastVisitedAtById: { ...current, [threadKey]: unreadAt } });
- @@ -0,0 +25,21 @@25+26+ const markThreadUnread = useCallback(() => {27+ if (!preferencesReady) return;28+ const unreadAt = resolveThreadUnreadAt(thread.latestTurn?.completedAt);29+ if (unreadAt !== undefined && unreadAt !== lastVisitedAt) {30+ savePreferences((preferences: Preferences) => ({31+ threadLastVisitedAtById: {32+ ...preferences.threadLastVisitedAtById,33+ [threadKey]: unreadAt,34+ },35+ }));36+ }37+ }, [lastVisitedAt, preferencesReady, savePreferences, thread.latestTurn?.completedAt, threadKey]);38+39+ const markThreadVisited = useCallback(() => {40+ if (!preferencesReady) return;41+ // A thread visited mid-turn has no completion to anchor to yet; stamp42+ // the visit time so a later completion still reads as unseen.43+ const visitedAt = resolveThreadVisitedAt(44+ lastVisitedAt,45+ thread.latestTurn?.completedAt ?? new Date().toISOString(),
anirudhsama(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.



📝 Walkthrough
Walkthrough#
Changes#
Mobile thread management
apps/mobile/src/components/ConfirmDialogHost.tsx,apps/mobile/src/features/home/...apps/mobile/src/features/threads/...Thread read-state synchronization
packages/client-runtime/src/state/...,packages/client-runtime/package.jsonapps/mobile/src/persistence/...,apps/mobile/src/state/...,apps/mobile/src/features/threads/...apps/web/src/components/...,apps/web/src/uiStateStore.tsAndroid menu rendering
apps/mobile/src/components/AndroidAnchoredMenu.tsx,apps/mobile/src/components/android-menu-sections.*apps/mobile/src/components/AppSymbol.tsxEstimated code review effort: 4 (Complex) | ~45 minutes
Merge Risk: 🟡 Moderate · up to
58f31Mobile users may miss unread completion state after viewing a running turn, and can trigger an Archive action that fails while work is active. Resolve these behavior mismatches before merging.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 31.82% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 23 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning
Tools execution failed with the following error:
Failed to run tools: Stream initialization permanently failed: 14 UNAVAILABLE: Connection dropped
Comment `@coderabbitai help` to get the list of available commands.