TypeScript
fix(mobile): unsent drafts lead the thread list, matching web (#19818)
Tristan Knighta064567a4760
diff --git a/apps/mobile/src/features/threads/threadListV2.test.ts b/apps/mobile/src/features/threads/threadListV2.test.tsindex 1e40dc937d2..cceb2e5f008 100644--- a/apps/mobile/src/features/threads/threadListV2.test.ts+++ b/apps/mobile/src/features/threads/threadListV2.test.ts@@ -1154,10 +1154,30 @@ describe("buildThreadListV2ListItems", () => {now: NOW,});- it("splices queued tasks between the active block and the settled tail", () => {+ it("leads the list with unsent drafts and queued tasks, preserving section dividers", () => {const items = buildThreadListV2ListItems({items: layout.items,- pendingTasks: [makePendingTask("queued-1"), makePendingTask("queued-2")],+ pendingTasks: [+ {+ kind: "draft",+ key: "draft-task:new-task:unsent",+ environmentId,+ projectId: ProjectId.make("project-1"),+ projectTitle: undefined,+ projectCwd: undefined,+ branch: null,+ title: "unsent",+ createdAt: NOW,+ draftKey: "new-task:unsent",+ draft: {+ text: "unsent",+ attachments: [],+ project: { environmentId, projectId: ProjectId.make("project-1"), createdAt: NOW },+ },+ },+ makePendingTask("queued-1"),+ makePendingTask("queued-2"),+ ],settledCount: layout.settledCount,settledShelfHeaderIndex: layout.settledShelfHeaderIndex,});@@ -1172,13 +1192,18 @@ describe("buildThreadListV2ListItems", () => {? "snoozed-shelf": "settled-shelf",),- ).toEqual(["active", "queued-1", "queued-2", "settled-shelf", "settled"]);+ ).toEqual(["unsent", "queued-1", "queued-2", "active", "settled-shelf", "settled"]);expect(- items.filter((item) => item.type === "v2-pending" && item.showPendingDivider),- ).toHaveLength(1);+ items.flatMap((item) => (item.type === "v2-pending" ? [item.showPendingDivider] : [])),+ ).toEqual([true, false, false]);+ expect(+ items.map((item) =>+ item.type === "v2-thread" || item.type === "v2-pending" ? item.showTrailingDivider : null,+ ),+ ).toEqual([true, true, true, false, null, false]);});- it("ends the list with queued tasks when nothing has settled yet", () => {+ it("puts queued tasks above active rows when nothing has settled yet", () => {const activeOnly = buildThreadListV2Items({threads: [makeThread({ id: ThreadId.make("active"), title: "active" })],environmentId: null,@@ -1190,7 +1215,7 @@ describe("buildThreadListV2ListItems", () => {pendingTasks: [makePendingTask("queued-1")],});- expect(items.map((item) => item.type)).toEqual(["v2-thread", "v2-pending"]);+ expect(items.map((item) => item.type)).toEqual(["v2-pending", "v2-thread"]);});it("keeps the settled shelf between active and settled rows when nothing is queued", () => {@@ -1208,7 +1233,7 @@ describe("buildThreadListV2ListItems", () => {]);});- it("places queued tasks before a collapsed snoozed shelf", () => {+ it("places queued tasks above active rows and a collapsed snoozed shelf", () => {const snoozedLayout = buildThreadListV2Items({threads: [makeThread({ id: ThreadId.make("active"), title: "active" }),@@ -1240,8 +1265,8 @@ describe("buildThreadListV2ListItems", () => {});expect(items.map((item) => item.type)).toEqual([- "v2-thread","v2-pending",+ "v2-thread","v2-snoozed-shelf","v2-settled-shelf","v2-thread",@@ -2132,7 +2157,7 @@ describe("buildThreadListV2ListItems trailing dividers", () => {const dividers = items.map((item) =>item.type === "v2-thread" || item.type === "v2-pending" ? item.showTrailingDivider : "n/a",);- expect(dividers).toEqual([true, false, true, false]);+ expect(dividers).toEqual([true, true, true, false]);});});@@ -2370,8 +2395,8 @@ describe("Working section beta", () => {: item.type,),).toEqual([- "active","queued",+ "active","v2-working-shelf","working","v2-snoozed-shelf",diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.tsindex 630ebb70e39..03a409e65ad 100644--- a/apps/mobile/src/features/threads/threadListV2.ts+++ b/apps/mobile/src/features/threads/threadListV2.ts@@ -476,7 +476,7 @@ export function buildThreadListV2ListItems(input: {const snoozedEnd = settledShelfHeaderIndex ?? threadItems.length;const workingEnd = snoozedShelfHeaderIndex ?? snoozedEnd;const activeEnd = workingShelfHeaderIndex ?? workingEnd;- const result: ThreadListV2ListItem[] = [...threadItems.slice(0, activeEnd), ...pendingItems];+ const result: ThreadListV2ListItem[] = [...pendingItems, ...threadItems.slice(0, activeEnd)];const shelfDisabled = input.shelfPreferencesLoading === true;if (workingShelfHeaderIndex !== null && workingCount > 0) {result.push({