The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 01:30 UTC
fix(mobile): add missing thread rename action (#11503)
Michel Liao committed
Sep 15, 2026 at 13:26 UTC
d1790aa14639a0361c02fbc5c326d0aa76f95a83
9 files changed
+190
-37
apps/mobile/src/components/ConfirmDialogHost.tsx
+63
-20
@@ -1,5 +1,5 @@
1
import { useCallback, useEffect, useState } from "react";
2
-import { Modal, Pressable, View } from "react-native";
2
+import { Modal, Pressable, TextInput, View } from "react-native";
3
4
import { cn } from "../lib/cn";
5
import { AppText } from "./AppText";
@@ -14,7 +14,20 @@ export type ConfirmDialogRequest = {
14
readonly onCancel?: () => void;
15
};
16
17
-let presentRequest: ((request: ConfirmDialogRequest) => void) | null = null;
17
+export type TextInputDialogRequest = {
18
+ readonly title: string;
19
+ readonly initialValue: string;
20
+ readonly cancelText?: string;
21
+ readonly confirmText: string;
22
+ readonly onConfirm: (value: string) => void;
23
+ readonly onCancel?: () => void;
24
+};
25
+
26
+type DialogRequest =
27
+ | { readonly kind: "confirm"; readonly request: ConfirmDialogRequest }
28
+ | { readonly kind: "text-input"; readonly request: TextInputDialogRequest };
29
+
30
+let presentRequest: ((request: DialogRequest) => void) | null = null;
31
32
/**
33
* Imperative confirm dialog, Alert.alert-shaped. Native iOS alerts already
@@ -23,7 +36,11 @@ let presentRequest: ((request: ConfirmDialogRequest) => void) | null = null;
36
* once. Requires ConfirmDialogHost to be mounted at the app root.
37
*/
38
export function showConfirmDialog(request: ConfirmDialogRequest): void {
26
- presentRequest?.(request);
39
+ presentRequest?.({ kind: "confirm", request });
40
+}
41
+
42
+export function showTextInputDialog(request: TextInputDialogRequest): void {
43
+ presentRequest?.({ kind: "text-input", request });
44
}
45
46
/**
@@ -33,42 +50,64 @@ export function showConfirmDialog(request: ConfirmDialogRequest): void {
50
* button color and a dimmer message than the title.
51
*/
52
export function ConfirmDialogHost() {
36
- const [request, setRequest] = useState<ConfirmDialogRequest | null>(null);
53
+ const [presented, setPresented] = useState<DialogRequest | null>(null);
54
+ const [inputValue, setInputValue] = useState("");
55
useEffect(() => {
38
- presentRequest = setRequest;
56
+ presentRequest = (request) => {
57
+ setInputValue(request.kind === "text-input" ? request.request.initialValue : "");
58
+ setPresented(request);
59
+ };
60
return () => {
61
presentRequest = null;
62
};
63
}, []);
64
65
const handleCancel = useCallback(() => {
45
- request?.onCancel?.();
46
- setRequest(null);
47
- }, [request]);
66
+ presented?.request.onCancel?.();
67
+ setPresented(null);
68
+ }, [presented]);
69
70
const handleConfirm = useCallback(() => {
50
- request?.onConfirm();
51
- setRequest(null);
52
- }, [request]);
71
+ if (presented?.kind === "confirm") {
72
+ presented.request.onConfirm();
73
+ } else if (presented?.kind === "text-input") {
74
+ presented.request.onConfirm(inputValue);
75
+ }
76
+ setPresented(null);
77
+ }, [inputValue, presented]);
78
+
79
+ const confirmDisabled = presented?.kind === "text-input" && inputValue.trim().length === 0;
80
81
return (
82
<Modal
56
- visible={request !== null}
83
+ visible={presented !== null}
84
transparent
85
animationType="fade"
86
statusBarTranslucent
87
navigationBarTranslucent
88
onRequestClose={handleCancel}
89
>
63
- {request === null ? null : (
90
+ {presented === null ? null : (
91
<View className="flex-1 items-center justify-center bg-backdrop px-8">
92
<View className="w-full rounded-[24px] bg-card px-6 pb-4 pt-5">
66
- <AppText className="text-lg font-t3-medium">{request.title}</AppText>
67
- {request.message === undefined ? null : (
93
+ <AppText className="text-lg font-t3-medium">{presented.request.title}</AppText>
94
+ {presented.kind === "confirm" && presented.request.message !== undefined ? (
95
<AppText className="mt-2 text-sm text-foreground-secondary">
69
- {request.message}
96
+ {presented.request.message}
97
</AppText>
71
- )}
98
+ ) : null}
99
+ {presented.kind === "text-input" ? (
100
+ <TextInput
101
+ accessibilityLabel={presented.request.title}
102
+ autoFocus
103
+ className="mt-4 rounded-xl border border-border bg-screen px-3 py-2.5 text-base text-foreground"
104
+ onChangeText={setInputValue}
105
+ onSubmitEditing={confirmDisabled ? undefined : handleConfirm}
106
+ returnKeyType="done"
107
+ selectTextOnFocus
108
+ value={inputValue}
109
+ />
110
+ ) : null}
111
<View className="mt-5 flex-row justify-end gap-1">
112
<View className="overflow-hidden rounded-full">
113
<Pressable
@@ -77,23 +116,27 @@ export function ConfirmDialogHost() {
116
onPress={handleCancel}
117
>
118
<AppText className="text-base font-t3-medium">
80
- {request.cancelText ?? "Cancel"}
119
+ {presented.request.cancelText ?? "Cancel"}
120
</AppText>
121
</Pressable>
122
</View>
123
<View className="overflow-hidden rounded-full">
124
<Pressable
125
accessibilityRole="button"
126
+ disabled={confirmDisabled}
127
className="min-h-10 items-center justify-center px-4 active:bg-subtle"
128
onPress={handleConfirm}
129
>
130
<AppText
131
className={cn(
132
"text-base font-t3-medium",
93
- request.destructive && "text-danger-foreground",
133
+ presented.kind === "confirm" &&
134
+ presented.request.destructive &&
135
+ "text-danger-foreground",
136
+ confirmDisabled && "text-foreground-tertiary",
137
)}
138
>
96
- {request.confirmText}
139
+ {presented.request.confirmText}
140
</AppText>
141
</Pressable>
142
</View>
apps/mobile/src/features/home/HomeRouteScreen.tsx
+2
@@ -50,6 +50,7 @@ export function HomeRouteScreen() {
50
pinThread,
51
unpinThread,
52
moveThread,
53
+ renameThread,
54
regenerateThreadTitle,
55
unsettleThread,
56
} = useThreadListActions();
@@ -200,6 +201,7 @@ export function HomeRouteScreen() {
201
onPinThread={pinThread}
202
onUnpinThread={unpinThread}
203
onMoveThread={moveThread}
204
+ onRenameThread={renameThread}
205
onRegenerateThreadTitle={regenerateThreadTitle}
206
onEnvironmentChange={setSelectedEnvironmentId}
207
onProjectChange={setSelectedProjectKey}
apps/mobile/src/features/home/HomeScreen.tsx
+9
@@ -126,6 +126,7 @@ interface HomeScreenProps {
126
thread: EnvironmentThreadShell,
127
direction: ThreadMoveDestination,
128
) => Promise<boolean>;
129
+ readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
130
readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => Promise<boolean>;
131
readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
132
readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
@@ -538,6 +539,10 @@ export function HomeScreen(props: HomeScreenProps) {
539
},
540
[props.onRegenerateThreadTitle],
541
);
542
+ const handleRenameThread = useCallback(
543
+ (thread: EnvironmentThreadShell) => props.onRenameThread(thread),
544
+ [props.onRenameThread],
545
+ );
546
const handleDeleteThread = props.onDeleteThread;
547
const handleUnsettleThread = props.onUnsettleThread;
548
// The settled tail renders in pages; expansion resets when the filter
@@ -868,6 +873,7 @@ export function HomeScreen(props: HomeScreenProps) {
873
onSelectThread={props.onSelectThread}
874
onDeleteThread={handleDeleteThread}
875
onArchiveThread={props.onArchiveThread}
876
+ onRenameThread={handleRenameThread}
877
onRegenerateThreadTitle={handleRegenerateThreadTitle}
878
titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
879
settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
@@ -901,6 +907,7 @@ export function HomeScreen(props: HomeScreenProps) {
907
handleMoveThread,
908
handlePinThread,
909
handleRegenerateThreadTitle,
910
+ handleRenameThread,
911
handleSettleThread,
912
handleSnoozeThread,
913
handleUnpinThread,
@@ -1025,6 +1032,7 @@ export function HomeScreen(props: HomeScreenProps) {
1032
searchQuery={props.searchQuery}
1033
onArchiveThread={props.onArchiveThread}
1034
onDeleteThread={props.onDeleteThread}
1035
+ onRenameThread={handleRenameThread}
1036
onRegenerateThreadTitle={handleRegenerateThreadTitle}
1037
titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
1038
onSelectThread={props.onSelectThread}
@@ -1049,6 +1057,7 @@ export function HomeScreen(props: HomeScreenProps) {
1057
handleSwipeableClose,
1058
handleSwipeableWillOpen,
1059
handleRegenerateThreadTitle,
1060
+ handleRenameThread,
1061
machineByEnvironmentId,
1062
queuedThreadKeys,
1063
props.onArchiveThread,
apps/mobile/src/features/home/useThreadListActions.ts
+49
-2
@@ -4,10 +4,10 @@ import { canSnooze, effectiveSnoozed } from "@t3tools/client-runtime/state/threa
4
import * as Cause from "effect/Cause";
5
import * as Haptics from "expo-haptics";
6
import { useCallback, useRef } from "react";
7
-import { Alert } from "react-native";
7
+import { Alert, Platform } from "react-native";
8
9
import { withThreadDismissal } from "./thread-dismissal";
10
-import { showConfirmDialog } from "../../components/ConfirmDialogHost";
10
+import { showConfirmDialog, showTextInputDialog } from "../../components/ConfirmDialogHost";
11
import { scopedThreadKey } from "../../lib/scopedEntities";
12
import { refreshArchivedThreadsForEnvironment } from "../archive/useArchivedThreadSnapshots";
13
import { pinOrderKeyBetween } from "@t3tools/client-runtime/state/thread-sort";
@@ -27,6 +27,7 @@ import {
27
threadDropLifecycle,
28
} from "../threads/threadOrder";
29
import { getThreadListV2OrderedSection } from "../threads/threadListV2";
30
+import { resolveThreadTitleRename } from "../threads/thread-title-rename";
31
32
/** Version skew: never send settle/unsettle to a server that predates them
33
(capability defaults false on decode for older servers). */
@@ -240,6 +241,7 @@ export function useThreadListActions(): {
241
thread: EnvironmentThreadShell,
242
direction: ThreadMoveDestination,
243
) => Promise<boolean>;
244
+ readonly renameThread: (thread: EnvironmentThreadShell) => void;
245
readonly regenerateThreadTitle: (thread: EnvironmentThreadShell) => Promise<boolean>;
246
} {
247
const executeAction = useThreadActionExecutor();
@@ -474,6 +476,50 @@ export function useThreadListActions(): {
476
},
477
[updateThreadMetadata],
478
);
479
+ const renameThread = useCallback(
480
+ (thread: EnvironmentThreadShell) => {
481
+ const commit = (title: string) => {
482
+ const resolution = resolveThreadTitleRename({ title, originalTitle: thread.title });
483
+ if (resolution.action === "reject-empty") {
484
+ Alert.alert("Could not rename thread", "Thread title cannot be empty.");
485
+ return;
486
+ }
487
+ if (resolution.action === "noop") return;
488
+ selectionHaptic();
489
+ void updateThreadMetadata({
490
+ environmentId: thread.environmentId,
491
+ input: { threadId: thread.id, title: resolution.title },
492
+ }).then((result) => {
493
+ if (result._tag === "Success") return;
494
+ const error = Cause.squash(result.cause);
495
+ Alert.alert(
496
+ "Could not rename thread",
497
+ error instanceof Error && error.message.trim().length > 0
498
+ ? error.message
499
+ : "The thread could not be renamed.",
500
+ );
501
+ });
502
+ };
503
+
504
+ if (Platform.OS === "ios") {
505
+ Alert.prompt(
506
+ "Rename thread",
507
+ undefined,
508
+ (title) => commit(title ?? ""),
509
+ "plain-text",
510
+ thread.title,
511
+ );
512
+ return;
513
+ }
514
+ showTextInputDialog({
515
+ title: "Rename thread",
516
+ initialValue: thread.title,
517
+ confirmText: "Rename",
518
+ onConfirm: commit,
519
+ });
520
+ },
521
+ [updateThreadMetadata],
522
+ );
523
524
// Plan against the complete section so filtering does not change a move.
525
const reorderPinnedMutation = useAtomCommand(threadEnvironment.reorderPin, {
@@ -653,6 +699,7 @@ export function useThreadListActions(): {
699
pinThread,
700
unpinThread,
701
moveThread,
702
+ renameThread,
703
regenerateThreadTitle,
704
};
705
}
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+4
@@ -171,6 +171,7 @@ function ThreadNavigationSidebarPane(
171
pinThread,
172
unpinThread,
173
moveThread,
174
+ renameThread,
175
regenerateThreadTitle,
176
} = useThreadListActions();
177
const threadListV2Enabled = useThreadListV2Enabled();
@@ -932,6 +933,7 @@ function ThreadNavigationSidebarPane(
933
onSelectThread={handleSelectThread}
934
onDeleteThread={confirmDeleteThread}
935
onArchiveThread={archiveThread}
936
+ onRenameThread={renameThread}
937
onRegenerateThreadTitle={regenerateThreadTitle}
938
titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
939
settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
@@ -1049,6 +1051,7 @@ function ThreadNavigationSidebarPane(
1051
fullSwipeWidth={props.width - 20}
1052
onArchiveThread={archiveThread}
1053
onDeleteThread={confirmDeleteThread}
1054
+ onRenameThread={renameThread}
1055
onRegenerateThreadTitle={regenerateThreadTitle}
1056
titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
1057
onSelectThread={handleSelectThread}
@@ -1091,6 +1094,7 @@ function ThreadNavigationSidebarPane(
1094
projectByKey,
1095
projectTitleByProjectKey,
1096
regenerateThreadTitle,
1097
+ renameThread,
1098
props.onNewThreadInProject,
1099
props.onNewThreadOnBranch,
1100
props.searchQuery,
apps/mobile/src/features/threads/thread-list-items.tsx
+8
-2
@@ -437,6 +437,7 @@ export const PendingTaskListRow = memo(function PendingTaskListRow(props: {
437
438
const THREAD_ROW_MENU_ACTIONS: MenuAction[] = [
439
{ id: "archive", title: "Archive", image: "archivebox" },
440
+ { id: "rename", title: "Rename", image: "square.and.pencil" },
441
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
442
];
443
@@ -458,6 +459,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
459
readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
460
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
461
readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
462
+ readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
463
readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => void;
464
readonly titleRegenerationSupported: boolean;
465
readonly onSwipeableWillOpen: (methods: SwipeableMethods) => void;
@@ -484,6 +486,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
486
onSelectThread,
487
onArchiveThread,
488
onDeleteThread,
489
+ onRenameThread,
490
onRegenerateThreadTitle,
491
onNewThreadOnBranch,
492
} = props;
@@ -525,6 +528,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
528
529
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
530
const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]);
531
+ const handleRename = useCallback(() => onRenameThread(thread), [onRenameThread, thread]);
532
const handleRegenerateTitle = useCallback(
533
() => onRegenerateThreadTitle(thread),
534
[onRegenerateThreadTitle, thread],
@@ -542,11 +546,12 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
546
]
547
: []),
548
THREAD_ROW_MENU_ACTIONS[0]!,
549
+ THREAD_ROW_MENU_ACTIONS[1]!,
550
...buildThreadTitleRegenerationMenuItems({
551
supported: props.titleRegenerationSupported,
552
isRegenerating: thread.titleRegeneration != null,
553
}),
549
- THREAD_ROW_MENU_ACTIONS[1]!,
554
+ THREAD_ROW_MENU_ACTIONS[2]!,
555
],
556
[props.titleRegenerationSupported, thread.branch, thread.titleRegeneration],
557
);
@@ -563,10 +568,11 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
568
({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
569
if (nativeEvent.event === "new-thread-on-branch") onNewThreadOnBranch(thread);
570
if (nativeEvent.event === "archive") handleArchive();
571
+ if (nativeEvent.event === "rename") handleRename();
572
if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
573
if (nativeEvent.event === "delete") handleDelete();
574
},
569
- [handleArchive, handleDelete, handleRegenerateTitle, onNewThreadOnBranch, thread],
575
+ [handleArchive, handleDelete, handleRegenerateTitle, handleRename, onNewThreadOnBranch, thread],
576
);
577
578
const statusPill = effectiveStatus ? (
apps/mobile/src/features/threads/thread-list-v2-items.tsx
+20
-13
@@ -382,6 +382,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
382
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
383
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
384
readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
385
+ readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
386
readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => void;
387
readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
388
readonly onSnoozeThread: (thread: EnvironmentThreadShell, snoozedUntil: string) => void;
@@ -423,6 +424,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
424
variant,
425
onSelectThread,
426
onDeleteThread,
427
+ onRenameThread,
428
onRegenerateThreadTitle,
429
onNewThreadOnBranch,
430
onSettleThread,
@@ -468,6 +470,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
470
settledTimestamp !== null ? relativeTime(settledTimestamp) : threadTimeLabel(thread);
471
472
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
473
+ const handleRename = useCallback(() => onRenameThread(thread), [onRenameThread, thread]);
474
const handleRegenerateTitle = useCallback(
475
() => onRegenerateThreadTitle(thread),
476
[onRegenerateThreadTitle, thread],
@@ -560,12 +563,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
563
variant,
564
],
565
);
563
- const titleRegenerationMenuItems = useMemo<MenuAction[]>(
564
- () =>
565
- buildThreadTitleRegenerationMenuItems({
566
+ const titleMenuItems = useMemo<MenuAction[]>(
567
+ () => [
568
+ { id: "rename", title: "Rename", image: "square.and.pencil" },
569
+ ...buildThreadTitleRegenerationMenuItems({
570
supported: props.titleRegenerationSupported,
571
isRegenerating: thread.titleRegeneration != null,
572
}),
573
+ ],
574
[props.titleRegenerationSupported, thread.titleRegeneration],
575
);
576
const snoozableCardMenuActions = useMemo<MenuAction[]>(
@@ -578,19 +583,19 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
583
subactions: snoozePresetActions,
584
},
585
...arrangementMenuItems,
581
- ...titleRegenerationMenuItems,
586
+ ...titleMenuItems,
587
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
588
],
584
- [arrangementMenuItems, snoozePresetActions, titleRegenerationMenuItems],
589
+ [arrangementMenuItems, snoozePresetActions, titleMenuItems],
590
);
591
const cardMenuActions = useMemo<MenuAction[]>(
592
() => [
593
CARD_MENU_ACTIONS[0]!,
594
...arrangementMenuItems,
590
- ...titleRegenerationMenuItems,
595
+ ...titleMenuItems,
596
...CARD_MENU_ACTIONS.slice(1),
597
],
593
- [arrangementMenuItems, titleRegenerationMenuItems],
598
+ [arrangementMenuItems, titleMenuItems],
599
);
600
const slimMenuActions = useMemo<MenuAction[]>(
601
() => [
@@ -598,23 +603,23 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
603
...arrangementMenuItems.filter(
604
(action) => action.id !== "move-up" && action.id !== "move-down",
605
),
601
- ...titleRegenerationMenuItems,
606
+ ...titleMenuItems,
607
SLIM_MENU_ACTIONS[1]!,
608
],
604
- [arrangementMenuItems, titleRegenerationMenuItems],
609
+ [arrangementMenuItems, titleMenuItems],
610
);
611
const snoozedMenuActions = useMemo<MenuAction[]>(
607
- () => [SNOOZED_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, SNOOZED_MENU_ACTIONS[1]!],
608
- [titleRegenerationMenuItems],
612
+ () => [SNOOZED_MENU_ACTIONS[0]!, ...titleMenuItems, SNOOZED_MENU_ACTIONS[1]!],
613
+ [titleMenuItems],
614
);
615
const legacyMenuActions = useMemo<MenuAction[]>(
616
() => [
617
LEGACY_MENU_ACTIONS[0]!,
618
...arrangementMenuItems,
614
- ...titleRegenerationMenuItems,
619
+ ...titleMenuItems,
620
LEGACY_MENU_ACTIONS[1]!,
621
],
617
- [arrangementMenuItems, titleRegenerationMenuItems],
622
+ [arrangementMenuItems, titleMenuItems],
623
);
624
const handleMenuAction = useCallback(
625
({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
@@ -628,6 +633,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
633
if (nativeEvent.event === "move-up") handleMoveUp();
634
if (nativeEvent.event === "move-down") handleMoveDown();
635
if (nativeEvent.event === "archive") handleArchive();
636
+ if (nativeEvent.event === "rename") handleRename();
637
if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
638
if (nativeEvent.event === "delete") handleDelete();
639
if (nativeEvent.event === "snooze:custom") {
@@ -651,6 +657,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
657
handleArchive,
658
handleDelete,
659
handleRegenerateTitle,
660
+ handleRename,
661
handleMoveDown,
662
handleMoveUp,
663
handlePin,
apps/mobile/src/features/threads/thread-title-rename.test.ts
new
+21
@@ -0,0 +1,21 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { resolveThreadTitleRename } from "./thread-title-rename";
4
+
5
+describe("resolveThreadTitleRename", () => {
6
+ it("trims a changed title", () => {
7
+ expect(resolveThreadTitleRename({ title: " New title ", originalTitle: "Old" })).toEqual({
8
+ action: "rename",
9
+ title: "New title",
10
+ });
11
+ });
12
+
13
+ it("rejects empty and unchanged titles", () => {
14
+ expect(resolveThreadTitleRename({ title: " ", originalTitle: "Old" })).toEqual({
15
+ action: "reject-empty",
16
+ });
17
+ expect(resolveThreadTitleRename({ title: " Old ", originalTitle: "Old" })).toEqual({
18
+ action: "noop",
19
+ });
20
+ });
21
+});
apps/mobile/src/features/threads/thread-title-rename.ts
new
+14
@@ -0,0 +1,14 @@
1
+export type ThreadTitleRenameResolution =
2
+ | { readonly action: "rename"; readonly title: string }
3
+ | { readonly action: "noop" }
4
+ | { readonly action: "reject-empty" };
5
+
6
+export function resolveThreadTitleRename(input: {
7
+ readonly title: string;
8
+ readonly originalTitle: string;
9
+}): ThreadTitleRenameResolution {
10
+ const title = input.title.trim();
11
+ if (title.length === 0) return { action: "reject-empty" };
12
+ if (title === input.originalTitle) return { action: "noop" };
13
+ return { action: "rename", title };
14
+}