Fakultas Ilmu Komputer UI

Commit 65a294db authored by wulanmantiri's avatar wulanmantiri
Browse files

[REFACTOR] Add toast for downloading files

parent 3a3a2623
import { PermissionsAndroid } from 'react-native'; import { PermissionsAndroid } from 'react-native';
import RNFetchBlob from 'rn-fetch-blob'; import RNFetchBlob from 'rn-fetch-blob';
import { FileType } from './schema'; import { FileType } from './schema';
import Toast from 'react-native-toast-message';
const useDownloadFiles = ( const useDownloadFiles = (
url = '', url = '',
...@@ -22,13 +23,19 @@ const useDownloadFiles = ( ...@@ -22,13 +23,19 @@ const useDownloadFiles = (
return; return;
} }
Toast.show({
type: 'success',
text1: `Mengunduh ${fileName}...`,
text2: 'Notifikasi akan muncul setelah unduh selesai. Mohon menunggu.',
});
const dirs = RNFetchBlob.fs.dirs; const dirs = RNFetchBlob.fs.dirs;
RNFetchBlob.config({ RNFetchBlob.config({
addAndroidDownloads: { addAndroidDownloads: {
useDownloadManager: true, useDownloadManager: true,
notification: true, notification: true,
mime: fileType, mime: fileType,
title: 'Mengunduh ' + title + '...', title: title || fileName,
mediaScannable: true, mediaScannable: true,
path: dirs.DownloadDir + `/${fileName}`, path: dirs.DownloadDir + `/${fileName}`,
}, },
......
...@@ -15,11 +15,7 @@ import { Props } from './types'; ...@@ -15,11 +15,7 @@ import { Props } from './types';
const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => { const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => {
const url = API_BASE_URL + data?.client_plan_meal; const url = API_BASE_URL + data?.client_plan_meal;
const { download, fileName } = useDownloadFiles( const { download, fileName } = useDownloadFiles(url, '', FileType.PDF);
url,
'rencana makan',
FileType.PDF,
);
const hasValues = (obj: DietRecommendationResponse) => const hasValues = (obj: DietRecommendationResponse) =>
[obj.client_plan_meal, obj.nutritional_advice, obj.lifestyle_advice].reduce( [obj.client_plan_meal, obj.nutritional_advice, obj.lifestyle_advice].reduce(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment