Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/mobile/src/features/threads/threadOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ export function computeThreadMoveAvailability(input: {
// A reorder in flight locks the whole list until its receipt lands.
if (input.pendingOrder != null) return result;
const rows = input.ordered;
// With no neighbor there is no up/down move, so skip the allThreads indexes.
if (rows.length < 2) {
for (const row of rows) result.set(rowId(row), { canMoveUp: false, canMoveDown: false });
return result;
}
const orderedIds = rows.map(rowId);
const indexById = new Map(orderedIds.map((id, index) => [id, index] as const));
const keysById = new Map(
Expand Down
28 changes: 28 additions & 0 deletions apps/mobile/src/features/threads/threadOrderAvailability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,34 @@ describe("computeThreadMoveAvailability matches the reference planner", () => {
expect(batch.get("env-w:t0")).toEqual({ canMoveUp: false, canMoveDown: false });
});

it("answers empty and single-row sections without consulting hidden rows", () => {
const hidden = [makeRow("h0", "env-w", "b", true), makeRow("h1", "env-x", null, true)];
expect(
computeThreadMoveAvailability({
ordered: [],
allThreads: hidden,
section: "pinned",
reorderableEnvironmentIds: WRITABLE,
}).size,
).toBe(0);
for (const environment of ["env-w", "env-x"]) {
const ordered = [makeRow("t0", environment, "a", true)];
const allThreads = [...ordered, ...hidden];
const batch = computeThreadMoveAvailability({
ordered,
allThreads,
section: "pinned",
reorderableEnvironmentIds: WRITABLE,
});
expect(Object.fromEntries(batch)).toEqual({
[`${environment}:t0`]: { canMoveUp: false, canMoveDown: false },
});
expect(Object.fromEntries(batch)).toEqual(
Object.fromEntries(referenceAvailability(ordered, allThreads, WRITABLE)),
);
}
});

it("denies rows whose section has non-writable neighbours when the fast path fails", () => {
// Keyless neighbors force the section-rewrite fallback; a non-writable
// neighbor makes the rewrite illegal for every row in the section.
Expand Down
Loading