Accept multiple images and videos in attachment picker

This commit is contained in:
Jamie Kyle 2022-09-15 14:40:48 -07:00 committed by GitHub
parent 6cfe2a09df
commit 01587b0f39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 87 additions and 54 deletions

View file

@ -15,7 +15,7 @@ import { handleImageAttachment } from './handleImageAttachment';
import { handleVideoAttachment } from './handleVideoAttachment';
import { isAttachmentSizeOkay } from './isAttachmentSizeOkay';
import { isFileDangerous } from './isFileDangerous';
import { isHeic, isImage, stringToMIMEType } from '../types/MIME';
import { isHeic, isImage, isVideo, stringToMIMEType } from '../types/MIME';
import { isImageTypeSupported, isVideoTypeSupported } from './GoogleChrome';
export function getPendingAttachment(
@ -57,19 +57,24 @@ export function preProcessAttachment(
return AttachmentToastType.ToastMaxAttachments;
}
const haveNonImage = draftAttachments.some(
(attachment: AttachmentDraftType) => !isImage(attachment.contentType)
const haveNonImageOrVideo = draftAttachments.some(
(attachment: AttachmentDraftType) => {
return (
!isImage(attachment.contentType) && !isVideo(attachment.contentType)
);
}
);
// You can't add another attachment if you already have a non-image staged
if (haveNonImage) {
return AttachmentToastType.ToastOneNonImageAtATime;
if (haveNonImageOrVideo) {
return AttachmentToastType.ToastUnsupportedMultiAttachment;
}
const fileType = stringToMIMEType(file.type);
const imageOrVideo = isImage(fileType) || isVideo(fileType);
// You can't add a non-image attachment if you already have attachments staged
if (!isImage(fileType) && draftAttachments.length > 0) {
return AttachmentToastType.ToastCannotMixImageAndNonImageAttachments;
if (!imageOrVideo && draftAttachments.length > 0) {
return AttachmentToastType.ToastCannotMixMultiAndNonMultiAttachments;
}
return undefined;