Skip to content

Commit

Permalink
feat: Display 'File not supported' error message when inserting an un…
Browse files Browse the repository at this point in the history
…supported file - EXO-75991 - Meeds-io/MIPs#145 (#1251)
  • Loading branch information
sofyenne committed Dec 13, 2024
1 parent c5ada87 commit 20fa398
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CKEDITOR.plugins.setLang('insertImage', 'en',
{
buttonTooltip: 'Insert image',
imageError: 'An error occurred while loading the image. Please try again'
imageError: 'An error occurred while loading the image. Please try again',
imageNotSupported: 'File not supported'
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CKEDITOR.plugins.setLang('insertImage', 'fr',
{
buttonTooltip: 'Insérer une image',
imageError: 'Une erreur est survenue lors du chargement de l\u2019image. Veuillez essayer de nouveau.'
imageError: 'Une erreur est survenue lors du chargement de l\u2019image. Veuillez essayer de nouveau.',
imageNotSupported: 'Format de fichier non supporté'
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
document.dispatchEvent(new CustomEvent('notes-editor-upload-done'));
editor.fire('change');
});
} else {
displayImageNotSupportedAlert();
}
};
}
Expand All @@ -55,6 +57,12 @@
return false;
}
}
function displayImageNotSupportedAlert() {
document.dispatchEvent(new CustomEvent('alert-message-html', {detail: {
alertType: 'error',
alertMessage: editor.lang.insertImage.imageNotSupported
}}));
}
function moveSelectionToDropPosition(editor, dropEvt) {
const $evt = dropEvt,
range = editor.createRange();
Expand Down Expand Up @@ -95,8 +103,7 @@
return;
}
event.preventDefault();
let files = Array.from(event.dataTransfer.files);
files = files.filter((file) => file.type.startsWith('image/'));
const files = Array.from(event.dataTransfer.files);
const dropSequentially = async () => {
document.dispatchEvent(new CustomEvent('notes-editor-upload-progress'));
for (let index = 0; index < files.length; index++) {
Expand All @@ -105,6 +112,8 @@
if (isSupportedType(file?.type)) {
// eslint-disable-next-line
await handleFileUpload(file, !isLast);
} else {
displayImageNotSupportedAlert();
}
}
};
Expand Down Expand Up @@ -258,7 +267,6 @@
// eslint-disable-next-line
await handleFileUpload(file, !isLast);
}

}
};
if (files.length > 0) {
Expand Down

0 comments on commit 20fa398

Please sign in to comment.