Skip to content

Commit

Permalink
fix: native picker max images (#2699)
Browse files Browse the repository at this point in the history
* fix: native image picker max images not respected

* chore: add comments for clarity

* chore: wrap max file text in translations

* chore: translations
  • Loading branch information
isekovanic authored Oct 3, 2024
1 parent 28b4198 commit 8d3ef4d
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Alert, ImageBackground, Platform, StyleSheet, Text, View } from 'react-
import { TouchableOpacity } from '@gorhom/bottom-sheet';
import { lookup } from 'mime-types';

import { useTranslationContext } from '../../../contexts';
import { AttachmentPickerContextValue } from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
import { useViewport } from '../../../hooks/useViewport';
Expand Down Expand Up @@ -39,6 +40,7 @@ const AttachmentVideo = (props: AttachmentVideoProps) => {
setSelectedFiles,
} = props;
const { vw } = useViewport();
const { t } = useTranslationContext();

const {
theme: {
Expand Down Expand Up @@ -76,7 +78,7 @@ const AttachmentVideo = (props: AttachmentVideoProps) => {

const updateSelectedFiles = async () => {
if (numberOfUploads >= maxNumberOfFiles) {
Alert.alert('Maximum number of files reached');
Alert.alert(t('Maximum number of files reached'));
return;
}
const files = await patchVideoFile(selectedFiles);
Expand Down Expand Up @@ -143,6 +145,7 @@ const AttachmentImage = (props: AttachmentImageProps) => {
},
} = useTheme();
const { vw } = useViewport();
const { t } = useTranslationContext();

const size = vw(100) / (numberOfAttachmentPickerImageColumns || 3) - 2;

Expand All @@ -165,7 +168,7 @@ const AttachmentImage = (props: AttachmentImageProps) => {

const updateSelectedImages = async () => {
if (numberOfUploads >= maxNumberOfFiles) {
Alert.alert('Maximum number of files reached');
Alert.alert(t('Maximum number of files reached'));
return;
}
const images = await patchImageFile(selectedImages);
Expand Down
14 changes: 13 additions & 1 deletion package/src/contexts/messageInputContext/MessageInputContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,19 @@ export const MessageInputProvider = <
],
);
}

// RN CLI
if (numberOfUploads >= value.maxNumberOfFiles) {
Alert.alert(t('Maximum number of files reached'));
return;
}

if (result.assets && result.assets.length > 0) {
// Expo
if (result.assets.length > value.maxNumberOfFiles) {
Alert.alert(t('Maximum number of files reached'));
return;
}
result.assets.forEach(async (asset) => {
if (asset.type.includes('image')) {
await uploadNewImage(asset);
Expand Down Expand Up @@ -746,7 +758,7 @@ export const MessageInputProvider = <
}

if (numberOfUploads >= value.maxNumberOfFiles) {
Alert.alert('Maximum number of files reached');
Alert.alert(t('Maximum number of files reached'));
return;
}

Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Loading messages...",
"Loading threads...": "Loading threads...",
"Loading...": "Loading...",
"Maximum number of files reached": "Maximum number of files reached",
"Message Reactions": "Message Reactions",
"Message deleted": "Message deleted",
"Message flagged": "Message flagged",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Cargando mensajes...",
"Loading threads...": "Cargando hilos...",
"Loading...": "Cargando...",
"Maximum number of files reached": "Número máximo de archivos alcanzado",
"Message Reactions": "Reacciones al mensaje",
"Message deleted": "Mensaje eliminado",
"Message flagged": "Mensaje reportado",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Chargement des messages...",
"Loading threads...": "Chargement des fils...",
"Loading...": "Chargement...",
"Maximum number of files reached": "Nombre maximal de fichiers atteint",
"Message Reactions": "Réactions aux messages",
"Message deleted": "Message supprimé",
"Message flagged": "Message signalé",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "ההודעות בטעינה..",
"Loading threads...": "טוען שרשורים...",
"Loading...": "טוען...",
"Maximum number of files reached": "הגעת למספר המרבי של קבצים",
"Message Reactions": "תגובות להודעה",
"Message deleted": "ההודעה נמחקה",
"Message flagged": "ההודעה סומנה",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "मेसेजस लोड हो रहे हैं...",
"Loading threads...": "थ्रेड्स लोड हो रहे हैं...",
"Loading...": "लोड हो रहा है...",
"Maximum number of files reached": "फ़ाइलों की अधिकतम संख्या पहुँच गई",
"Message Reactions": "संदेश प्रतिक्रियाएँ",
"Message deleted": "मैसेज हटा दिया गया",
"Message flagged": "संदेश को ध्वजांकित किया गया",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Caricamento messaggi...",
"Loading threads...": "Caricamento dei thread...",
"Loading...": "Caricamento...",
"Maximum number of files reached": "Numero massimo di file raggiunto",
"Message Reactions": "Reazioni ai Messaggi",
"Message deleted": "Messaggio cancellato",
"Message flagged": "Messaggio contrassegnato",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "メッセージを読み込み中。。。",
"Loading threads...": "スレッドを読み込み中...",
"Loading...": "読み込み中。。。",
"Maximum number of files reached": "ファイルの最大数に達しました",
"Message Reactions": "メッセージのリアクション",
"Message deleted": "メッセージが削除されました",
"Message flagged": "メッセージにフラグが付けられました",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "메시지를 로딩 중...",
"Loading threads...": "스레드 로딩 중...",
"Loading...": "로딩 중...",
"Maximum number of files reached": "최대 파일 수에 도달했습니다",
"Message Reactions": "메시지의 리액션",
"Message deleted": "메시지가 삭제되었습니다.",
"Message flagged": "메시지에 플래그가 지정되었습니다",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Berichten aan het laden...",
"Loading threads...": "Threads laden...",
"Loading...": "Aan het laden...",
"Maximum number of files reached": "Maximaal aantal bestanden bereikt",
"Message Reactions": "Bericht Reacties",
"Message deleted": "Bericht verwijderd",
"Message flagged": "Bericht gemarkeerd",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Carregando mensagens...",
"Loading threads...": "Carregando tópicos...",
"Loading...": "Carregando...",
"Maximum number of files reached": "Número máximo de arquivos atingido",
"Message Reactions": "Reações à Mensagem",
"Message deleted": "Mensagem excluída",
"Message flagged": "Mensagem sinalizada",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Загружаю сообщения...",
"Loading threads...": "Загрузка потоков...",
"Loading...": "Загружаю...",
"Maximum number of files reached": "Достигнуто максимальное количество файлов",
"Message Reactions": "Сообщения Реакции",
"Message deleted": "Сообщение удалено",
"Message flagged": "Сообщение отмечено",
Expand Down
1 change: 1 addition & 0 deletions package/src/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Loading messages...": "Mesajlar yükleniyor...",
"Loading threads...": "Akışlar yükleniyor...",
"Loading...": "Yükleniyor...",
"Maximum number of files reached": "Maksimum dosya sayısına ulaşıldı",
"Message Reactions": "Mesaj Tepkileri",
"Message deleted": "Mesaj silindi",
"Message flagged": "Mesaj işaretlendi",
Expand Down

0 comments on commit 8d3ef4d

Please sign in to comment.