Remove debugging statements.

This commit is contained in:
Patrick Fic
2024-02-29 15:32:28 -08:00
parent 43280e3f3d
commit fa14c76268
3 changed files with 59 additions and 155 deletions

View File

@@ -1,5 +1,5 @@
import * as MediaLibrary from "expo-media-library";
import React, { useEffect, useState } from "react";
import * as MediaLibrary from 'expo-media-library';
import React, { useEffect, useState } from 'react';
import {
ActivityIndicator,
@@ -8,20 +8,20 @@ import {
StyleSheet,
Text,
View,
} from "react-native";
import { ProgressBar } from "react-native-paper";
import Toast from "react-native-toast-message";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { logImEXEvent } from "../../firebase/firebase.analytics";
} from 'react-native';
import { ProgressBar } from 'react-native-paper';
import Toast from 'react-native-toast-message';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { logImEXEvent } from '../../firebase/firebase.analytics';
import {
selectCurrentCameraJobId,
selectDeleteAfterUpload,
} from "../../redux/app/app.selectors";
} from '../../redux/app/app.selectors';
import * as Sentry from '@sentry/react-native';
import { formatBytes } from "../../util/document-upload.utility";
import { handleLocalUpload } from "../../util/local-document-upload.utility";
import { formatBytes } from '../../util/document-upload.utility';
import { handleLocalUpload } from '../../util/local-document-upload.utility';
const mapStateToProps = createStructuredSelector({
selectedCameraJobId: selectCurrentCameraJobId,
@@ -54,7 +54,7 @@ export function UploadProgress({
async function handleOnSuccess({ duration, data }) {
//If it's not in production, show a toast with the time.
Toast.show({
type: "success",
type: 'success',
text1: ` Upload completed in ${duration}.`,
//
// text2: duration,
@@ -63,45 +63,27 @@ export function UploadProgress({
try {
await MediaLibrary.deleteAssetsAsync(data);
try {
const album = await MediaLibrary.createAlbumAsync(
'ImEX Mobile Deleted',
data.pop(),
const album = await MediaLibrary.createAlbumAsync(
'ImEX Mobile Deleted',
data.pop(),
false
);
//Move the rest.
if (data.length > 0) {
const moveResult = await MediaLibrary.addAssetsToAlbumAsync(
data,
album,
false
);
//Move the rest.
if (data.length > 0) {
const moveResult = await MediaLibrary.addAssetsToAlbumAsync(
data,
album,
false
);
}
const deleteResult = await MediaLibrary.deleteAlbumsAsync(album);
Toast.show({
type: 'success',
text1: 'Pictures deleted succesfully.',
text2: JSON.stringify(deleteResult),
autoHide: false,
});
} catch (error) {
console.log("🚀 ~ onDone ~ error:", error)
Toast.show({
type: 'error',
text1: 'deleteAlbumsAsync',
text2: JSON.stringify(error),
autoHide: false,
});
}
const deleteResult = await MediaLibrary.deleteAlbumsAsync(album);
} catch (error) {
console.log("Unable to delete picture.", error);
console.log('Unable to delete picture.', error);
Sentry.Native.captureException(error);
}
}
logImEXEvent("imexmobile_successful_upload");
logImEXEvent('imexmobile_successful_upload');
forceRerender();
setProgress({ ...progress, speed: 0, percent: 1, uploadInProgress: false });
}
@@ -116,10 +98,10 @@ export function UploadProgress({
}
function handleOnError({ assetid, error }) {
logImEXEvent("imexmobile_upload_documents_error");
logImEXEvent('imexmobile_upload_documents_error');
Toast.show({
type: "error",
text1: "Unable to upload documents.",
type: 'error',
text1: 'Unable to upload documents.',
text2: error,
autoHide: false,
});
@@ -148,7 +130,7 @@ export function UploadProgress({
onSuccess: ({ duration }) => handleOnSuccess({ duration, data }),
context: {
jobid:
selectedCameraJobId !== "temp" ? selectedCameraJobId : "temporary",
selectedCameraJobId !== 'temp' ? selectedCameraJobId : 'temporary',
},
});
};
@@ -156,41 +138,41 @@ export function UploadProgress({
return (
<Modal
visible={progress.uploadInProgress}
animationType="slide"
animationType='slide'
transparent={true}
onRequestClose={() => {
Alert.alert("Cancel?", "Do you want to abort the upload?", [
Alert.alert('Cancel?', 'Do you want to abort the upload?', [
{
text: "Yes",
text: 'Yes',
onPress: () => {
setUploads(null);
setProgress(null);
},
},
{ text: "No" },
{ text: 'No' },
]);
}}
>
<View style={styles.modalContainer}>
<View style={styles.modal}>
<ActivityIndicator style={{ alignSelf: "center", marginTop: 16 }} />
<ActivityIndicator style={{ alignSelf: 'center', marginTop: 16 }} />
<ProgressBar
progress={progress.percent}
style={{ alignSelf: "center", marginTop: 16 }}
color={progress.percent === 1 ? "green" : "blue"}
style={{ alignSelf: 'center', marginTop: 16 }}
color={progress.percent === 1 ? 'green' : 'blue'}
/>
<Text style={{ alignSelf: "center", marginTop: 16 }}>{`${formatBytes(
<Text style={{ alignSelf: 'center', marginTop: 16 }}>{`${formatBytes(
progress.speed
)}/sec`}</Text>
<Text
style={{ alignSelf: "center", marginTop: 16 }}
style={{ alignSelf: 'center', marginTop: 16 }}
>{`Avg. ${formatBytes(
progress.loaded / ((new Date() - progress.start) / 1000)
)}/sec`}</Text>
<Text
style={{ alignSelf: "center", marginTop: 16 }}
style={{ alignSelf: 'center', marginTop: 16 }}
>{`Total Uploaded ${formatBytes(progress.loaded)}`}</Text>
<Text style={{ alignSelf: "center", marginTop: 16 }}>{`Duration ${(
<Text style={{ alignSelf: 'center', marginTop: 16 }}>{`Duration ${(
(new Date() - progress.start) /
1000
).toFixed(1)} sec`}</Text>
@@ -201,19 +183,19 @@ export function UploadProgress({
}
const styles = StyleSheet.create({
modalContainer: {
display: "flex",
display: 'flex',
flex: 1,
justifyContent: "center",
justifyContent: 'center',
},
modal: {
// flex: 1,
display: "flex",
display: 'flex',
marginLeft: 20,
marginRight: 20,
backgroundColor: "white",
backgroundColor: 'white',
borderRadius: 20,
padding: 18,
shadowColor: "#000",
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,

View File

@@ -208,100 +208,22 @@ export function UploadProgress({
//Create a new asset with the first file to delete.
// console.log('Trying new delete.');
await MediaLibrary.getPermissionsAsync(false);
// try {
// const albumremove = await MediaLibrary.removeAssetsFromAlbumAsync(
// filesToDelete,
// filesToDelete[0].albumId
// );
// Toast.show({
// type: 'info',
// text1: 'removeAssetsFromAlbumAsync',
// text2: JSON.stringify(albumremove),
// autoHide: false,
// });
// } catch (error) {
// console.log("🚀 ~ onDone ~ error:", error)
// Toast.show({
// type: 'error',
// text1: 'removeAssetsFromAlbumAsync',
// text2: JSON.stringify(error),
// autoHide: false,
// });
// }
// try {
// const delres = await MediaLibrary.deleteAssetsAsync(
// filesToDelete.map((f) => f.id)
// );
// Toast.show({
// type: 'info',
// text1: 'deleteAssetsAsync',
// text2: JSON.stringify(delres),
// autoHide: false,
// });
// } catch (error) {
// console.log("🚀 ~ onDone ~ error:", error)
// Toast.show({
// type: 'error',
// text1: 'deleteAssetsAsync',
// text2: JSON.stringify(error),
// autoHide: false,
// });
// }
// try {
// const res = Promise.all(
// filesToDelete.map((f) =>
// FileSystem.deleteAsync(f.uri, { idempotent: true })
// )
// );
// Toast.show({
// type: 'info',
// text1: 'FileSystemDelete',
// text2: JSON.stringify(res),
// autoHide: false,
// });
// } catch (error) {
// console.log("🚀 ~ onDone ~ error:", error)
// Toast.show({
// type: 'error',
// text1: 'FileSystemDelete',
// text2: JSON.stringify(error),
// autoHide: false,
// });
// }
try {
const album = await MediaLibrary.createAlbumAsync(
'ImEX Mobile Deleted',
filesToDelete.pop(),
const album = await MediaLibrary.createAlbumAsync(
'ImEX Mobile Deleted',
filesToDelete.pop(),
false
);
//Move the rest.
if (filesToDelete.length > 0) {
const moveResult = await MediaLibrary.addAssetsToAlbumAsync(
filesToDelete,
album,
false
);
//Move the rest.
if (filesToDelete.length > 0) {
const moveResult = await MediaLibrary.addAssetsToAlbumAsync(
filesToDelete,
album,
false
);
}
const deleteResult = await MediaLibrary.deleteAlbumsAsync(album);
Toast.show({
type: 'success',
text1: 'Pictures deleted succesfully.',
text2: JSON.stringify(deleteResult),
autoHide: false,
});
} catch (error) {
console.log("🚀 ~ onDone ~ error:", error)
Toast.show({
type: 'error',
text1: 'deleteAlbumsAsync',
text2: JSON.stringify(error),
autoHide: false,
});
}
const deleteResult = await MediaLibrary.deleteAlbumsAsync(album);
//Delete the album.
//This defaults to delete all assets in the album.