Files
webmail/lib/compose/attachment-order.ts
T
Linus Rath d03d4a0b78 fix: show whole rows of attachments and keep uploading files in their place
The attachment order test now expects uploading files where they were
added: moved to the front, a big upload jumped out of sight once done.
2026-11-04 12:33:28 +01:00

16 lines
671 B
TypeScript

/**
* The composer's attachment chips in the order they're shown: failed first,
* then the rest in the order added. A file still uploading keeps its place:
* moved to the front, it jumped to the end once done and went out of sight
* past the rows on screen (compose-p2-11). `index` is the place in the
* composer's list.
*/
export function attachmentsForDisplay<T extends { error?: unknown; uploading?: boolean }>(
attachments: readonly T[],
): Array<{ att: T; index: number }> {
const rank = (att: T) => (att.error ? 0 : 1);
return attachments
.map((att, index) => ({ att, index }))
.sort((a, b) => rank(a.att) - rank(b.att) || a.index - b.index);
}