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 handleItems = (e) => {
const { items } = e.clipboardData || e.dataTransfer; const { items } = e.clipboardData || e.dataTransfer;
const files = []; const files = [];
const unattachableFiles = [];
const unsupportedFiles = []; const unsupportedFiles = [];
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
const item = items[i]; const item = items[i];
if (item.kind === 'file') { if (item.kind === 'file') {
const file = item.getAsFile(); const file = item.getAsFile();
if (!file) { if (!file) {
alert(t`Unable to attach file.`); unattachableFiles.push(file);
return;
} }
else if (supportedMimeTypes !== undefined && !supportedMimeTypes.includes(file.type)) { else if (supportedMimeTypes !== undefined && !supportedMimeTypes.includes(file.type)) {
unsupportedFiles.push(file); 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) { if (unsupportedFiles.length > 0) {
alert( alert(
plural(unsupportedFiles.length, { plural(unsupportedFiles.length, {