Move unattachable files outside of the loop

This commit is contained in:
Stefano Pigozzi 2024-09-07 23:15:20 +02:00
parent 28f87e2c8a
commit e77219cff3
No known key found for this signature in database
GPG key ID: 5ADA3868646C3FC0

View file

@ -600,14 +600,14 @@ function Compose({
const handleItems = (e) => {
const { items } = e.clipboardData || e.dataTransfer;
const files = [];
const unattachableFiles = [];
const unsupportedFiles = [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.kind === 'file') {
const file = item.getAsFile();
if (!file) {
alert(t`Unable to attach file.`);
return;
unattachableFiles.push(file);
}
else if (supportedMimeTypes !== undefined && !supportedMimeTypes.includes(file.type)) {
unsupportedFiles.push(file);
@ -617,6 +617,14 @@ function Compose({
}
}
}
if (unattachableFiles.length > 0) {
alert(
plural(unattachableFiles.length, {
one: `Couldn't attach file ${unsupportedFiles[0]}.`,
other: `Couldn't attach files ${unsupportedFiles.join(", ")}.`,
})
)
}
if (unsupportedFiles.length > 0) {
alert(
plural(unsupportedFiles.length, {