Skip to content

Commit 5374f0d

Browse files
committed
fix(mobile): retain arrangement drafts when saving fails
1 parent 6a05f52 commit 5374f0d

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

‎apps/mobile/src/features/home/useThreadListActions.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ vi.mock("../../state/threads", () => ({
141141
}));
142142

143143
import { useArchivedThreadListActions, useThreadListActions } from "./useThreadListActions";
144+
import { scopedThreadKey } from "../../lib/scopedEntities";
144145

145146
const primaryEnvironmentId = EnvironmentId.make("primary");
146147
const otherEnvironmentId = EnvironmentId.make("other");
@@ -183,6 +184,49 @@ beforeEach(() => {
183184

184185
afterEach(() => vi.unstubAllEnvs());
185186

187+
describe("thread arrangement save recovery", () => {
188+
it("retries failed moves without repeating confirmed moves from another environment", async () => {
189+
const primary = makeThread({
190+
pinnedAt: "2026-10-15T00:00:00.000Z",
191+
pinOrderKey: "a",
192+
});
193+
const other = makeThread({ ...primary, environmentId: otherEnvironmentId });
194+
state.shells = [primary, other];
195+
const drafts = new Map([
196+
[scopedThreadKey(primary.environmentId, primary.id), { pinOrderKey: "c" }],
197+
[scopedThreadKey(other.environmentId, other.id), { pinOrderKey: "d" }],
198+
]);
199+
state.afterRequest = () => {
200+
state.shells = [{ ...primary, pinOrderKey: "c" }, other];
201+
};
202+
const { saveThreadArrangement } = useThreadListActions();
203+
204+
expect(await saveThreadArrangement(drafts)).toBe(false);
205+
expect(state.dropBusy).toBe(false);
206+
expect(state.requests).toEqual([
207+
{
208+
action: "reorderPin",
209+
environmentId: primaryEnvironmentId,
210+
input: { threadId: primary.id, orderKey: "c" },
211+
},
212+
]);
213+
214+
state.requests = [];
215+
state.scopes.get(otherEnvironmentId)!.add(AuthOrchestrationOperateScope);
216+
state.afterRequest = undefined;
217+
218+
expect(await saveThreadArrangement(drafts)).toBe(true);
219+
expect(state.dropBusy).toBe(false);
220+
expect(state.requests).toEqual([
221+
{
222+
action: "reorderPin",
223+
environmentId: otherEnvironmentId,
224+
input: { threadId: other.id, orderKey: "d" },
225+
},
226+
]);
227+
});
228+
});
229+
186230
describe("thread list operation permissions", () => {
187231
it.each(mutationCases)(
188232
"%s rejects a retained callback after its environment loses permission",

‎apps/mobile/src/features/threads/ThreadArrangementSheet.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,11 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
263263
if (saving) return;
264264
stop();
265265
setSaving(true);
266-
await saveThreadArrangement(drafts);
267-
props.onClose();
266+
try {
267+
if (await saveThreadArrangement(drafts)) props.onClose();
268+
} finally {
269+
setSaving(false);
270+
}
268271
}
269272

270273
function stop() {

0 commit comments

Comments
 (0)