From 54e6ed8ebc3db55521c1f36009274dd858a3166c Mon Sep 17 00:00:00 2001 From: Hailey Date: Fri, 29 Dec 2023 22:00:52 -0800 Subject: [PATCH] ensure no more than four assets, show toast if more --- src/lib/media/picker.shared.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/media/picker.shared.ts b/src/lib/media/picker.shared.ts index 00b09c6b..8bade34e 100644 --- a/src/lib/media/picker.shared.ts +++ b/src/lib/media/picker.shared.ts @@ -4,6 +4,7 @@ import { MediaTypeOptions, } from 'expo-image-picker' import {getDataUriSize} from './util' +import * as Toast from 'view/com/util/Toast' export async function openPicker(opts?: ImagePickerOptions) { const response = await launchImageLibraryAsync({ @@ -13,7 +14,11 @@ export async function openPicker(opts?: ImagePickerOptions) { ...opts, }) - return (response.assets ?? []).map(image => ({ + if (response.assets && response.assets.length > 4) { + Toast.show('You may only select up to 4 images') + } + + return (response.assets ?? []).slice(0, 4).map(image => ({ mime: 'image/jpeg', height: image.height, width: image.width,