From 9552577c3b2b1030c9f7d208da9aae23496dd502 Mon Sep 17 00:00:00 2001 From: Abdelrahman Khattab Date: Tue, 9 Jan 2024 00:35:54 +0200 Subject: [PATCH 1/4] Add a custom success message for QR download --- .../QRShare/QRShareWithDownload/index.native.js | 6 ++++-- src/languages/en.ts | 1 + src/libs/fileDownload/FileUtils.ts | 5 +++-- src/libs/fileDownload/index.android.ts | 8 ++++---- src/libs/fileDownload/index.ios.ts | 4 ++-- src/libs/fileDownload/types.ts | 2 +- src/libs/localFileDownload/index.android.ts | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/components/QRShare/QRShareWithDownload/index.native.js b/src/components/QRShare/QRShareWithDownload/index.native.js index e64c7b69df4a..02d47f00b17f 100644 --- a/src/components/QRShare/QRShareWithDownload/index.native.js +++ b/src/components/QRShare/QRShareWithDownload/index.native.js @@ -2,20 +2,22 @@ import React, {forwardRef, useImperativeHandle, useRef} from 'react'; import ViewShot from 'react-native-view-shot'; import getQrCodeFileName from '@components/QRShare/getQrCodeDownloadFileName'; import {qrShareDefaultProps, qrSharePropTypes} from '@components/QRShare/propTypes'; +import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import fileDownload from '@libs/fileDownload'; import QRShare from '..'; function QRShareWithDownload({innerRef, ...props}) { const {isOffline} = useNetwork(); + const {translate} = useLocalize(); const qrCodeScreenshotRef = useRef(null); useImperativeHandle( innerRef, () => ({ - download: () => qrCodeScreenshotRef.current.capture().then((uri) => fileDownload(uri, getQrCodeFileName(props.title))), + download: () => qrCodeScreenshotRef.current.capture().then((uri) => fileDownload(uri, getQrCodeFileName(props.title), translate('fileDownload.success.qrMessage'))), }), - [props.title], + [props.title, translate], ); return ( diff --git a/src/languages/en.ts b/src/languages/en.ts index 83d244262e8a..0f8adbc1b576 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1790,6 +1790,7 @@ export default { success: { title: 'Downloaded!', message: 'Attachment successfully downloaded!', + qrMessage: 'Check your photos or downloads folder for a copy of your QR code. \nProtip: Add it to a presentation for your audience to scan and connect with you directly.', }, generalError: { title: 'Attachment Error', diff --git a/src/libs/fileDownload/FileUtils.ts b/src/libs/fileDownload/FileUtils.ts index 09cc1222310f..055abf140e64 100644 --- a/src/libs/fileDownload/FileUtils.ts +++ b/src/libs/fileDownload/FileUtils.ts @@ -7,11 +7,12 @@ import type {ReadFileAsync, SplitExtensionFromFileName} from './types'; /** * Show alert on successful attachment download + * @param successMessage */ -function showSuccessAlert() { +function showSuccessAlert(successMessage?: string) { Alert.alert( Localize.translateLocal('fileDownload.success.title'), - Localize.translateLocal('fileDownload.success.message'), + successMessage ?? Localize.translateLocal('fileDownload.success.message'), [ { text: Localize.translateLocal('common.ok'), diff --git a/src/libs/fileDownload/index.android.ts b/src/libs/fileDownload/index.android.ts index 577a42dd14a3..7c9d3caf6865 100644 --- a/src/libs/fileDownload/index.android.ts +++ b/src/libs/fileDownload/index.android.ts @@ -33,7 +33,7 @@ function hasAndroidPermission(): Promise { /** * Handling the download */ -function handleDownload(url: string, fileName: string): Promise { +function handleDownload(url: string, fileName: string, successMessage?: string): Promise { return new Promise((resolve) => { const dirs = RNFetchBlob.fs.dirs; @@ -84,7 +84,7 @@ function handleDownload(url: string, fileName: string): Promise { if (attachmentPath) { RNFetchBlob.fs.unlink(attachmentPath); } - FileUtils.showSuccessAlert(); + FileUtils.showSuccessAlert(successMessage); }) .catch(() => { FileUtils.showGeneralErrorAlert(); @@ -96,12 +96,12 @@ function handleDownload(url: string, fileName: string): Promise { /** * Checks permission and downloads the file for Android */ -const fileDownload: FileDownload = (url, fileName) => +const fileDownload: FileDownload = (url, fileName, successMessage) => new Promise((resolve) => { hasAndroidPermission() .then((hasPermission) => { if (hasPermission) { - return handleDownload(url, fileName); + return handleDownload(url, fileName, successMessage); } FileUtils.showPermissionErrorAlert(); }) diff --git a/src/libs/fileDownload/index.ios.ts b/src/libs/fileDownload/index.ios.ts index 7672b4b14926..4990c389fd9f 100644 --- a/src/libs/fileDownload/index.ios.ts +++ b/src/libs/fileDownload/index.ios.ts @@ -69,7 +69,7 @@ function downloadVideo(fileUrl: string, fileName: string): Promise { /** * Download the file based on type(image, video, other file types)for iOS */ -const fileDownload: FileDownload = (fileUrl, fileName) => +const fileDownload: FileDownload = (fileUrl, fileName, successMessage) => new Promise((resolve) => { let fileDownloadPromise; const fileType = FileUtils.getFileType(fileUrl); @@ -93,7 +93,7 @@ const fileDownload: FileDownload = (fileUrl, fileName) => return; } - FileUtils.showSuccessAlert(); + FileUtils.showSuccessAlert(successMessage); }) .catch((err) => { // iOS shows permission popup only once. Subsequent request will only throw an error. diff --git a/src/libs/fileDownload/types.ts b/src/libs/fileDownload/types.ts index bc8ba0807eb1..6d92bddd5816 100644 --- a/src/libs/fileDownload/types.ts +++ b/src/libs/fileDownload/types.ts @@ -1,6 +1,6 @@ import type {Asset} from 'react-native-image-picker'; -type FileDownload = (url: string, fileName: string) => Promise; +type FileDownload = (url: string, fileName: string, successMessage?: string) => Promise; type ImageResolution = {width: number; height: number}; type GetImageResolution = (url: File | Asset) => Promise; diff --git a/src/libs/localFileDownload/index.android.ts b/src/libs/localFileDownload/index.android.ts index b6d8ea13738f..dd266d3be405 100644 --- a/src/libs/localFileDownload/index.android.ts +++ b/src/libs/localFileDownload/index.android.ts @@ -7,7 +7,7 @@ import type LocalFileDownload from './types'; * and textContent, so we're able to copy it to the Android public download dir. * After the file is copied, it is removed from the internal dir. */ -const localFileDownload: LocalFileDownload = (fileName, textContent) => { +const localFileDownload: LocalFileDownload = (fileName, textContent, successMessage) => { const newFileName = FileUtils.appendTimeToFileName(fileName); const dir = RNFetchBlob.fs.dirs.DocumentDir; const path = `${dir}/${newFileName}.txt`; @@ -23,7 +23,7 @@ const localFileDownload: LocalFileDownload = (fileName, textContent) => { path, ) .then(() => { - FileUtils.showSuccessAlert(); + FileUtils.showSuccessAlert(successMessage); }) .catch(() => { FileUtils.showGeneralErrorAlert(); From 1026c5c1222be735baad9a43cb7e9559fb819633 Mon Sep 17 00:00:00 2001 From: Abdelrahman Khattab Date: Tue, 9 Jan 2024 00:45:35 +0200 Subject: [PATCH 2/4] add custom message to the download qr success action --- .../QRShare/QRShareWithDownload/index.native.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/QRShare/QRShareWithDownload/index.native.tsx b/src/components/QRShare/QRShareWithDownload/index.native.tsx index d1d9f13147f1..7d192c84c454 100644 --- a/src/components/QRShare/QRShareWithDownload/index.native.tsx +++ b/src/components/QRShare/QRShareWithDownload/index.native.tsx @@ -3,6 +3,7 @@ import React, {forwardRef, useImperativeHandle, useRef} from 'react'; import ViewShot from 'react-native-view-shot'; import getQrCodeFileName from '@components/QRShare/getQrCodeDownloadFileName'; import type {QRShareProps} from '@components/QRShare/types'; +import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import fileDownload from '@libs/fileDownload'; import QRShare from '..'; @@ -10,14 +11,16 @@ import type QRShareWithDownloadHandle from './types'; function QRShareWithDownload(props: QRShareProps, ref: ForwardedRef) { const {isOffline} = useNetwork(); + const {translate} = useLocalize(); + const qrCodeScreenshotRef = useRef(null); useImperativeHandle( ref, () => ({ - download: () => qrCodeScreenshotRef.current?.capture?.().then((uri) => fileDownload(uri, getQrCodeFileName(props.title))), + download: () => qrCodeScreenshotRef.current?.capture?.().then((uri) => fileDownload(uri, getQrCodeFileName(props.title), translate('fileDownload.success.qrMessage'))), }), - [props.title], + [props.title, translate], ); return ( From 5f1bca91b73daa035f358ffcfbc1f2821379ae9b Mon Sep 17 00:00:00 2001 From: Abdelrahman Khattab Date: Wed, 10 Jan 2024 01:05:06 +0200 Subject: [PATCH 3/4] adding spanish translation --- src/languages/en.ts | 2 +- src/languages/es.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index c635e58244f7..1f7b40dee9cd 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1796,7 +1796,7 @@ export default { success: { title: 'Downloaded!', message: 'Attachment successfully downloaded!', - qrMessage: 'Check your photos or downloads folder for a copy of your QR code. \nProtip: Add it to a presentation for your audience to scan and connect with you directly.', + qrMessage: 'Check your photos or downloads folder for a copy of your QR code. Protip: Add it to a presentation for your audience to scan and connect with you directly.', }, generalError: { title: 'Attachment Error', diff --git a/src/languages/es.ts b/src/languages/es.ts index eda992589f69..148ff7c5ec7a 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1822,6 +1822,8 @@ export default { success: { title: '!Descargado!', message: 'Archivo descargado correctamente', + qrMessage: + 'Busca la copia de tu código QR en la carpeta de fotos o descargas. Consejo: Añádelo a una presentación para que el público pueda escanearlo y conectar contigo directamente.', }, generalError: { title: 'Error en la descarga', From 3cf66f44c1f39e77309c068cb492cbd6ce7b3e19 Mon Sep 17 00:00:00 2001 From: Abdelrahman Khattab Date: Wed, 10 Jan 2024 01:10:21 +0200 Subject: [PATCH 4/4] Minor update --- src/libs/localFileDownload/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/localFileDownload/types.ts b/src/libs/localFileDownload/types.ts index 2086e2334d39..68e013e60bb3 100644 --- a/src/libs/localFileDownload/types.ts +++ b/src/libs/localFileDownload/types.ts @@ -1,3 +1,3 @@ -type LocalFileDownload = (fileName: string, textContent: string) => void; +type LocalFileDownload = (fileName: string, textContent: string, successMessage?: string) => void; export default LocalFileDownload;