Skip to content

Commit def6577

Browse files
fix(mobile): new threads no longer flash an Unsent row in the sidebar
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2922e8f commit def6577

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎apps/mobile/src/state/pending-new-tasks-model.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
1+
import { CommandId, EnvironmentId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

44
import {
5+
buildPendingNewTasks,
56
type PendingDraftProjectDefaults,
67
pendingDraftBranchNeedsRefs,
78
resolvePendingDraftBranch,
89
} from "./pending-new-tasks-model";
10+
import type { QueuedThreadMessage } from "./thread-outbox-model";
911
import type { ComposerDraft, ComposerDraftWorkspaceSelection } from "./use-composer-drafts";
1012

1113
const projectCwd = "/repo";
@@ -82,3 +84,33 @@ describe("resolvePendingDraftBranch", () => {
8284
expect(resolve({ draft: chosen, branches, projectCwd })).toBe("release");
8385
});
8486
});
87+
88+
function queuedCreation(environmentId: string): QueuedThreadMessage {
89+
return {
90+
environmentId: EnvironmentId.make(environmentId),
91+
threadId: ThreadId.make(`thread-${environmentId}`),
92+
messageId: MessageId.make(`message-${environmentId}`),
93+
commandId: CommandId.make(`command-${environmentId}`),
94+
text: "Test",
95+
attachments: [],
96+
creation: {
97+
projectId: ProjectId.make("project-1"),
98+
workspaceMode: "local",
99+
branch: null,
100+
worktreePath: null,
101+
},
102+
createdAt: "2026-11-10T01:10:00.000Z",
103+
};
104+
}
105+
106+
describe("buildPendingNewTasks", () => {
107+
it("lists only creations waiting for their environment to reconnect", () => {
108+
const tasks = buildPendingNewTasks({
109+
queuedMessages: [queuedCreation("online"), queuedCreation("offline")],
110+
drafts: {},
111+
connectedEnvironmentIds: new Set([EnvironmentId.make("online")]),
112+
});
113+
114+
expect(tasks.map((task) => task.environmentId)).toEqual(["offline"]);
115+
});
116+
});

‎apps/mobile/src/state/pending-new-tasks-model.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ export function resolvePendingDraftBranch(input: {
8888
export function buildPendingNewTasks(input: {
8989
readonly queuedMessages: ReadonlyArray<QueuedThreadMessage>;
9090
readonly drafts: Readonly<Record<string, ComposerDraft>>;
91+
readonly connectedEnvironmentIds: ReadonlySet<EnvironmentId>;
9192
}): ReadonlyArray<PendingNewTask> {
9293
const tasks: PendingNewTask[] = [];
9394
for (const message of input.queuedMessages) {
94-
if (!message.creation) {
95+
// A connected environment is delivering it now; listing it would flash an "Unsent" row.
96+
if (!message.creation || input.connectedEnvironmentIds.has(message.environmentId)) {
9597
continue;
9698
}
9799
tasks.push({

‎apps/mobile/src/state/use-pending-new-tasks.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useAtomValue } from "@effect/atom-react";
22
import { threadKey } from "@t3tools/client-runtime/state/entities";
33
import { buildPendingNewTasks, type PendingNewTask } from "./pending-new-tasks-model";
4+
import { connectedEnvironmentIdsAtom } from "./presentation";
45
import { flattenQueuedThreadMessages } from "./thread-outbox-model";
56
import { environmentThreadShells } from "./threads";
67
import { newTaskComposerDraftsAtom } from "./use-composer-drafts";
@@ -16,9 +17,14 @@ export function usePendingNewTasks(): ReadonlyArray<PendingNewTask> {
1617
const queuedMessagesByThreadKey = useThreadOutboxMessages();
1718
const drafts = useAtomValue(newTaskComposerDraftsAtom);
1819
const hiddenKeys = useAtomValue(environmentThreadShells.hiddenThreadKeysAtom);
20+
const connectedEnvironmentIds = useAtomValue(connectedEnvironmentIdsAtom);
1921
// A delivered creation can stay queued after its thread is live and hidden.
2022
const queuedMessages = flattenQueuedThreadMessages(queuedMessagesByThreadKey).filter(
2123
(message) => !hiddenKeys.has(threadKey(message)),
2224
);
23-
return buildPendingNewTasks({ queuedMessages, drafts });
25+
return buildPendingNewTasks({
26+
queuedMessages,
27+
drafts,
28+
connectedEnvironmentIds: new Set(connectedEnvironmentIds),
29+
});
2430
}

0 commit comments

Comments
 (0)