Improve cloudinary media upload experience.
This commit is contained in:
26
App.js
26
App.js
@@ -13,7 +13,7 @@ import "intl/locale-data/jsonp/en";
|
|||||||
import "./translations/i18n";
|
import "./translations/i18n";
|
||||||
import "expo-asset";
|
import "expo-asset";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
|
import { SafeAreaProvider } from "react-native-safe-area-context";
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
dsn: "https://8d6c3de1940a4e4f8b81cf4d2150bdea@o492140.ingest.sentry.io/5558869",
|
dsn: "https://8d6c3de1940a4e4f8b81cf4d2150bdea@o492140.ingest.sentry.io/5558869",
|
||||||
enableInExpoDevelopment: true,
|
enableInExpoDevelopment: true,
|
||||||
@@ -26,7 +26,7 @@ const theme = {
|
|||||||
...DefaultTheme,
|
...DefaultTheme,
|
||||||
colors: {
|
colors: {
|
||||||
...DefaultTheme.colors,
|
...DefaultTheme.colors,
|
||||||
primary: "dodgerblue",
|
primary: "#1890ff",
|
||||||
accent: "tomato",
|
accent: "tomato",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -38,16 +38,18 @@ export default class App extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
<SafeAreaProvider>
|
||||||
<PersistGate persistor={persistor}>
|
<Provider store={store}>
|
||||||
<ApolloProvider client={client}>
|
<PersistGate persistor={persistor}>
|
||||||
<PaperProvider theme={theme}>
|
<ApolloProvider client={client}>
|
||||||
<ScreenMainComponent />
|
<PaperProvider theme={theme}>
|
||||||
<Toast />
|
<ScreenMainComponent />
|
||||||
</PaperProvider>
|
<Toast />
|
||||||
</ApolloProvider>
|
</PaperProvider>
|
||||||
</PersistGate>
|
</ApolloProvider>
|
||||||
</Provider>
|
</PersistGate>
|
||||||
|
</Provider>
|
||||||
|
</SafeAreaProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as MediaLibrary from "expo-media-library";
|
import * as MediaLibrary from "expo-media-library";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import {
|
import {
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Alert,
|
Alert,
|
||||||
@@ -18,16 +18,11 @@ import {
|
|||||||
selectCurrentCameraJobId,
|
selectCurrentCameraJobId,
|
||||||
selectDeleteAfterUpload,
|
selectDeleteAfterUpload,
|
||||||
} from "../../redux/app/app.selectors";
|
} from "../../redux/app/app.selectors";
|
||||||
import {
|
|
||||||
selectBodyshop,
|
|
||||||
selectCurrentUser,
|
|
||||||
} from "../../redux/user/user.selectors";
|
|
||||||
import { formatBytes } from "../../util/document-upload.utility";
|
import { formatBytes } from "../../util/document-upload.utility";
|
||||||
import { handleLocalUpload } from "../../util/local-document-upload.utility";
|
import { handleLocalUpload } from "../../util/local-document-upload.utility";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
|
||||||
bodyshop: selectBodyshop,
|
|
||||||
selectedCameraJobId: selectCurrentCameraJobId,
|
selectedCameraJobId: selectCurrentCameraJobId,
|
||||||
deleteAfterUpload: selectDeleteAfterUpload,
|
deleteAfterUpload: selectDeleteAfterUpload,
|
||||||
});
|
});
|
||||||
@@ -35,8 +30,6 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
export default connect(mapStateToProps, null)(UploadProgress);
|
export default connect(mapStateToProps, null)(UploadProgress);
|
||||||
|
|
||||||
export function UploadProgress({
|
export function UploadProgress({
|
||||||
currentUser,
|
|
||||||
bodyshop,
|
|
||||||
selectedCameraJobId,
|
selectedCameraJobId,
|
||||||
deleteAfterUpload,
|
deleteAfterUpload,
|
||||||
uploads,
|
uploads,
|
||||||
@@ -49,8 +42,6 @@ export function UploadProgress({
|
|||||||
speed: 0,
|
speed: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//Set the state of uploads to do.
|
//Set the state of uploads to do.
|
||||||
if (uploads) {
|
if (uploads) {
|
||||||
|
|||||||
@@ -169,25 +169,23 @@ export function ScreenMainComponent({
|
|||||||
}, [checkUserSession]);
|
}, [checkUserSession]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={{ flex: 1 }}>
|
<NavigationContainer>
|
||||||
<NavigationContainer>
|
{currentUser.authorized === null ? (
|
||||||
{currentUser.authorized === null ? (
|
<ScreenSplash />
|
||||||
<ScreenSplash />
|
) : currentUser.authorized ? (
|
||||||
) : currentUser.authorized ? (
|
bodyshop ? (
|
||||||
bodyshop ? (
|
HasAccess(bodyshop) ? (
|
||||||
HasAccess(bodyshop) ? (
|
<BottomTabsNavigator />
|
||||||
<BottomTabsNavigator />
|
|
||||||
) : (
|
|
||||||
<ScreenSplash noAccess />
|
|
||||||
)
|
|
||||||
) : (
|
) : (
|
||||||
<ScreenSplash />
|
<ScreenSplash noAccess />
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<ScreenSignIn />
|
<ScreenSplash />
|
||||||
)}
|
)
|
||||||
</NavigationContainer>
|
) : (
|
||||||
</SafeAreaView>
|
<ScreenSignIn />
|
||||||
|
)}
|
||||||
|
</NavigationContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import {
|
|||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
import { formatBytes, handleUpload } from "../../util/document-upload.utility";
|
import { formatBytes, handleUpload } from "../../util/document-upload.utility";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
import { validateArgCount } from "@firebase/util";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
@@ -44,12 +46,17 @@ export function UploadProgress({
|
|||||||
selectedCameraJobId,
|
selectedCameraJobId,
|
||||||
deleteAfterUpload,
|
deleteAfterUpload,
|
||||||
uploads,
|
uploads,
|
||||||
|
setUploads,
|
||||||
forceRerender,
|
forceRerender,
|
||||||
}) {
|
}) {
|
||||||
const [progress, setProgress] = useState({
|
const [progress, setProgress] = useState({
|
||||||
loading: false,
|
|
||||||
uploadInProgress: false,
|
uploadInProgress: false,
|
||||||
speed: 0,
|
totalToUpload: 0,
|
||||||
|
totalUploaded: 0,
|
||||||
|
startTime: null,
|
||||||
|
totalFiles: 0,
|
||||||
|
totalFilesCompleted: 0,
|
||||||
|
currentFile: null,
|
||||||
files: {}, //uri is the key, value is progress
|
files: {}, //uri is the key, value is progress
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,65 +66,71 @@ export function UploadProgress({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//Set the state of uploads to do.
|
if (uploads) {
|
||||||
|
onDone(uploads);
|
||||||
if (uploads) onDone(uploads);
|
setUploads(null);
|
||||||
|
}
|
||||||
}, [uploads]);
|
}, [uploads]);
|
||||||
|
|
||||||
//if (!uploads) return null;
|
function handleOnSuccess(asset) {
|
||||||
|
//NEEDS REDO.
|
||||||
function handleOnSuccess(id, asset) {
|
|
||||||
logImEXEvent("imexmobile_successful_upload");
|
|
||||||
filesToDelete.push(asset);
|
filesToDelete.push(asset);
|
||||||
setProgress((progress) => ({
|
setProgress((progress) => ({
|
||||||
...progress,
|
...progress,
|
||||||
action: t("mediabrowser.labels.converting"),
|
// totalUploaded: progress.totalToUpload + asset.size,
|
||||||
|
totalFilesCompleted: progress.totalFilesCompleted + 1,
|
||||||
files: {
|
files: {
|
||||||
...progress.files,
|
...progress.files,
|
||||||
[id]: {
|
[asset.uri]: {
|
||||||
...progress.files[id],
|
...progress.files[asset.uri],
|
||||||
percent: 1,
|
uploadEnd: new Date(),
|
||||||
action: t("mediabrowser.labels.converting"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// });
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleOnProgress(uri, percent, loaded) {
|
|
||||||
setProgress((progress) => ({
|
|
||||||
...progress,
|
|
||||||
speed: loaded - progress.files[uri].loaded,
|
|
||||||
action:
|
|
||||||
percent === 1
|
|
||||||
? t("mediabrowser.labels.converting")
|
|
||||||
: t("mediabrowser.labels.uploading"),
|
|
||||||
files: {
|
|
||||||
...progress.files,
|
|
||||||
[uri]: {
|
|
||||||
...progress.files[uri],
|
|
||||||
percent,
|
|
||||||
speed: loaded - progress.files[uri].loaded,
|
|
||||||
action:
|
|
||||||
percent === 1
|
|
||||||
? t("mediabrowser.labels.converting")
|
|
||||||
: t("mediabrowser.labels.uploading"),
|
|
||||||
loaded: loaded,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
function handleOnError(...props) {
|
|
||||||
logImEXEvent("imexmobile_upload_documents_error", { props });
|
|
||||||
}
|
|
||||||
|
|
||||||
const onDone = async (data) => {
|
function handleOnProgress({ uri, filename }, percent, loaded) {
|
||||||
//Validate to make sure the totals for the file sizes do not exceed the total on the job.
|
//NEED REDO
|
||||||
setProgress({
|
setProgress((progress) => {
|
||||||
files: _.keyBy(data, "id"),
|
return {
|
||||||
loading: true,
|
...progress,
|
||||||
uploadInProgress: true,
|
totalUploaded:
|
||||||
|
progress.totalUploaded +
|
||||||
|
(loaded - (progress.files[uri]?.loaded || 0)),
|
||||||
|
files: {
|
||||||
|
...progress.files,
|
||||||
|
[uri]: {
|
||||||
|
...progress.files[uri],
|
||||||
|
percent,
|
||||||
|
filename,
|
||||||
|
speed: loaded - (progress.files[uri]?.loaded || 0),
|
||||||
|
loaded: loaded,
|
||||||
|
uploadStart: progress.files[uri]?.uploadStart || new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
function handleOnError(error) {
|
||||||
|
logImEXEvent("imexmobile_upload_documents_error", { error });
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Unable to upload documents.",
|
||||||
|
text2: error,
|
||||||
|
autoHide: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const onDone = async (selectedFiles) => {
|
||||||
|
//Validate to make sure the totals for the file sizes do not exceed the total on the job.
|
||||||
|
const data = [];
|
||||||
|
const totalOfUploads = await selectedFiles.reduce(async (acc, val) => {
|
||||||
|
//Get the size of the file based on URI.
|
||||||
|
const info = await FileSystem.getInfoAsync(val.uri, { size: true });
|
||||||
|
data.push({ ...info, ...val }); //Add in the size.
|
||||||
|
val.albumId && MediaLibrary.migrateAlbumIfNeededAsync(val.albumId);
|
||||||
|
return (await acc) + info.size;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
if (selectedCameraJobId !== "temp") {
|
if (selectedCameraJobId !== "temp") {
|
||||||
const queryData = await client.query({
|
const queryData = await client.query({
|
||||||
@@ -127,13 +140,6 @@ export function UploadProgress({
|
|||||||
jobId: selectedCameraJobId,
|
jobId: selectedCameraJobId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const totalOfUploads = await data.reduce(async (acc, val) => {
|
|
||||||
//Get the size of the file based on URI.
|
|
||||||
const info = await FileSystem.getInfoAsync(val.uri, { size: true });
|
|
||||||
|
|
||||||
val.albumId && MediaLibrary.migrateAlbumIfNeededAsync(val.albumId);
|
|
||||||
return (await acc) + info.size;
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
bodyshop.jobsizelimit -
|
bodyshop.jobsizelimit -
|
||||||
@@ -145,7 +151,7 @@ export function UploadProgress({
|
|||||||
...progress,
|
...progress,
|
||||||
speed: 0,
|
speed: 0,
|
||||||
action: null,
|
action: null,
|
||||||
loading: false,
|
|
||||||
uploadInProgress: false,
|
uploadInProgress: false,
|
||||||
}));
|
}));
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
@@ -155,10 +161,26 @@ export function UploadProgress({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//We made it this far. We have enough space, so let's start uploading.
|
||||||
|
|
||||||
//Sequentially await the proms.
|
setProgress((progress) => {
|
||||||
|
return {
|
||||||
|
...progress,
|
||||||
|
uploadInProgress: true,
|
||||||
|
|
||||||
|
totalToUpload: totalOfUploads,
|
||||||
|
totalUploaded: 0,
|
||||||
|
totalFilesCompleted: 0,
|
||||||
|
startTime: new Date(),
|
||||||
|
totalFiles: data.length,
|
||||||
|
currentFile: null,
|
||||||
|
files: {}, //uri is the key, value is progress
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
for (var i = 0; i < data.length + 4; i = i + 4) {
|
for (var i = 0; i < data.length + 4; i = i + 4) {
|
||||||
|
//Reset the files.
|
||||||
|
setProgress((progress) => ({ ...progress, files: {} }));
|
||||||
let proms = [];
|
let proms = [];
|
||||||
if (data[i]) {
|
if (data[i]) {
|
||||||
proms.push(CreateUploadProm(data[i]));
|
proms.push(CreateUploadProm(data[i]));
|
||||||
@@ -176,48 +198,51 @@ export function UploadProgress({
|
|||||||
await Promise.all(proms);
|
await Promise.all(proms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Everything is uploaded, delete the succesful ones.
|
||||||
if (deleteAfterUpload) {
|
if (deleteAfterUpload) {
|
||||||
try {
|
try {
|
||||||
|
console.log("Trying to Delete", filesToDelete);
|
||||||
if (Platform.OS === "android") {
|
if (Platform.OS === "android") {
|
||||||
const res = await Promise.all(
|
await Promise.all(
|
||||||
filesToDelete.map(async (f) =>
|
filesToDelete.map(async (f) =>
|
||||||
MediaLibrary.removeAssetsFromAlbumAsync(f, f.albumId)
|
MediaLibrary.removeAssetsFromAlbumAsync(f, f.albumId)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
console.log(
|
||||||
const deleteResult = await MediaLibrary.deleteAssetsAsync(
|
"Delete Result",
|
||||||
filesToDelete
|
await MediaLibrary.deleteAssetsAsync(filesToDelete.map((f) => f.id))
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Unable to delete picture.", error);
|
console.log("Unable to delete picture.", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filesToDelete = [];
|
filesToDelete = [];
|
||||||
setProgress({
|
|
||||||
loading: false,
|
|
||||||
speed: 0,
|
|
||||||
action: null,
|
|
||||||
|
|
||||||
|
//Reset state.
|
||||||
|
|
||||||
|
setProgress({
|
||||||
uploadInProgress: false,
|
uploadInProgress: false,
|
||||||
files: {}, //uri is the key, value is progress
|
totalToUpload: 0,
|
||||||
|
totalUploaded: 0,
|
||||||
|
totalFilesCompleted: 0,
|
||||||
|
startTime: null,
|
||||||
|
totalFiles: 0,
|
||||||
|
currentFile: null,
|
||||||
|
files: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
forceRerender();
|
forceRerender();
|
||||||
};
|
};
|
||||||
|
|
||||||
const CreateUploadProm = async (p) => {
|
const CreateUploadProm = async (p) => {
|
||||||
let filename;
|
return handleUpload(
|
||||||
filename = p.filename || p.uri.split("/").pop();
|
|
||||||
|
|
||||||
await handleUpload(
|
|
||||||
{
|
{
|
||||||
filename,
|
|
||||||
mediaId: p.id,
|
mediaId: p.id,
|
||||||
onError: handleOnError,
|
onError: handleOnError,
|
||||||
onProgress: ({ percent, loaded }) =>
|
onProgress: ({ percent, loaded }) =>
|
||||||
handleOnProgress(p.id, percent, loaded),
|
handleOnProgress(p, percent, loaded),
|
||||||
onSuccess: () => handleOnSuccess(p.id, p),
|
onSuccess: () => handleOnSuccess(p),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
bodyshop: bodyshop,
|
bodyshop: bodyshop,
|
||||||
@@ -226,20 +251,6 @@ export function UploadProgress({
|
|||||||
photo: p,
|
photo: p,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//Set the state to mark that it's done.
|
|
||||||
setProgress((progress) => ({
|
|
||||||
...progress,
|
|
||||||
action: null,
|
|
||||||
speed: 0,
|
|
||||||
files: {
|
|
||||||
...progress.files,
|
|
||||||
[p.id]: {
|
|
||||||
...progress.files[p.id],
|
|
||||||
action: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -248,15 +259,22 @@ export function UploadProgress({
|
|||||||
animationType="slide"
|
animationType="slide"
|
||||||
transparent={true}
|
transparent={true}
|
||||||
onRequestClose={() => {
|
onRequestClose={() => {
|
||||||
Alert.alert("Modal has been closed.");
|
Alert.alert("Cancel?", "Do you want to abort the upload?", [
|
||||||
|
{
|
||||||
|
text: "Yes",
|
||||||
|
onPress: () => {
|
||||||
|
setUploads(null);
|
||||||
|
setProgress(null);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ text: "No" },
|
||||||
|
]);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<View style={styles.modal}>
|
<View style={styles.modalContainer}>
|
||||||
{progress.loading && <ActivityIndicator />}
|
<View style={styles.modal}>
|
||||||
|
|
||||||
<ScrollView contentContainerStyle={styles.centeredView}>
|
|
||||||
{Object.keys(progress.files).map((key) => (
|
{Object.keys(progress.files).map((key) => (
|
||||||
<View key={progress.files[key].id} style={styles.progressItem}>
|
<View key={key} style={styles.progressItem}>
|
||||||
<Text style={styles.progressText}>
|
<Text style={styles.progressText}>
|
||||||
{progress.files[key].filename}
|
{progress.files[key].filename}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -266,24 +284,49 @@ export function UploadProgress({
|
|||||||
style={styles.progress}
|
style={styles.progress}
|
||||||
color={progress.files[key].percent === 1 ? "green" : "blue"}
|
color={progress.files[key].percent === 1 ? "green" : "blue"}
|
||||||
/>
|
/>
|
||||||
{progress.files[key].speed !== 0 &&
|
<View
|
||||||
progress.files[key].speed &&
|
style={{
|
||||||
!isNaN(progress.files[key].speed) ? (
|
display: "flex",
|
||||||
<Text>{`${formatBytes(progress.files[key].speed)}/sec`}</Text>
|
flexDirection: "row",
|
||||||
) : null}
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text>{`${formatBytes(
|
||||||
|
progress.files[key].loaded /
|
||||||
|
(((progress.files[key].uploadEnd || new Date()) -
|
||||||
|
progress.files[key].uploadStart) /
|
||||||
|
1000)
|
||||||
|
)}/sec`}</Text>
|
||||||
|
{progress.files[key].percent === 1 && (
|
||||||
|
<>
|
||||||
|
<ActivityIndicator style={{ marginLeft: 12 }} />
|
||||||
|
<Text style={{ marginLeft: 4 }}>Processing...</Text>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
</ScrollView>
|
<View style={styles.centeredView}>
|
||||||
|
<Text>{`${progress.totalFilesCompleted} of ${progress.totalFiles} uploaded.`}</Text>
|
||||||
|
<Text>{`${formatBytes(progress.totalUploaded)} of ${formatBytes(
|
||||||
|
progress.totalToUpload
|
||||||
|
)} uploaded.`}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
modal: {
|
modalContainer: {
|
||||||
|
display: "flex",
|
||||||
flex: 1,
|
flex: 1,
|
||||||
marginTop: 50,
|
justifyContent: "center",
|
||||||
marginBottom: 60,
|
},
|
||||||
|
modal: {
|
||||||
|
//flex: 1,
|
||||||
|
display: "flex",
|
||||||
marginLeft: 20,
|
marginLeft: 20,
|
||||||
marginRight: 20,
|
marginRight: 20,
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
@@ -299,9 +342,8 @@ const styles = StyleSheet.create({
|
|||||||
elevation: 5,
|
elevation: 5,
|
||||||
},
|
},
|
||||||
centeredView: {
|
centeredView: {
|
||||||
flex: 1,
|
justifyContent: "center",
|
||||||
// justifyContent: "center",
|
alignItems: "center",
|
||||||
// alignItems: "center",
|
|
||||||
marginTop: 22,
|
marginTop: 22,
|
||||||
},
|
},
|
||||||
progressItem: {
|
progressItem: {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
"expo-media-library": "~14.1.0",
|
"expo-media-library": "~14.1.0",
|
||||||
"expo-permissions": "~13.2.0",
|
"expo-permissions": "~13.2.0",
|
||||||
"expo-status-bar": "~1.3.0",
|
"expo-status-bar": "~1.3.0",
|
||||||
|
"expo-system-ui": "~1.2.0",
|
||||||
"expo-updates": "~0.13.2",
|
"expo-updates": "~0.13.2",
|
||||||
"expo-video-thumbnails": "~6.3.0",
|
"expo-video-thumbnails": "~6.3.0",
|
||||||
"firebase": "^9.8.3",
|
"firebase": "^9.8.3",
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ var cleanAxios = axios.create();
|
|||||||
cleanAxios.interceptors.request.eject(axiosAuthInterceptorId);
|
cleanAxios.interceptors.request.eject(axiosAuthInterceptorId);
|
||||||
|
|
||||||
export const handleUpload = async (ev, context) => {
|
export const handleUpload = async (ev, context) => {
|
||||||
const { filename, mediaId, onError, onSuccess, onProgress } = ev;
|
const { mediaId, onError, onSuccess, onProgress } = ev;
|
||||||
const { bodyshop, jobId } = context;
|
const { bodyshop, jobId } = context;
|
||||||
|
|
||||||
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
||||||
const newFile = await (await fetch(imageData.localUri)).blob();
|
const newFile = await (await fetch(imageData.uri)).blob();
|
||||||
let extension = imageData.localUri.split(".").pop();
|
let extension = imageData.localUri.split(".").pop();
|
||||||
let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace(
|
let key = `${bodyshop.id}/${jobId}/${newFile.data.name.replace(
|
||||||
/\.[^/.]+$/,
|
/\.[^/.]+$/,
|
||||||
""
|
""
|
||||||
)}-${new Date().getTime()}`;
|
)}-${new Date().getTime()}`;
|
||||||
@@ -29,8 +29,8 @@ export const handleUpload = async (ev, context) => {
|
|||||||
mediaId,
|
mediaId,
|
||||||
imageData,
|
imageData,
|
||||||
extension,
|
extension,
|
||||||
newFile.type,
|
newFile.type, //Filetype
|
||||||
newFile,
|
newFile, //File
|
||||||
onError,
|
onError,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onProgress,
|
onProgress,
|
||||||
@@ -51,30 +51,21 @@ export const uploadToCloudinary = async (
|
|||||||
onProgress,
|
onProgress,
|
||||||
context
|
context
|
||||||
) => {
|
) => {
|
||||||
const { bodyshop, jobId, billId, uploaded_by, callback, tagsArray, photo } =
|
const { bodyshop, jobId, uploaded_by } = context;
|
||||||
context;
|
|
||||||
|
|
||||||
//Set variables for getting the signed URL.
|
//Set variables for getting the signed URL.
|
||||||
let timestamp = Math.floor(Date.now() / 1000);
|
let timestamp = Math.floor(Date.now() / 1000);
|
||||||
let public_id = key;
|
let public_id = key;
|
||||||
let tags = `${bodyshop.textid},${
|
|
||||||
tagsArray ? tagsArray.map((tag) => `${tag},`) : ""
|
|
||||||
}`;
|
|
||||||
// let eager = process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS;
|
|
||||||
|
|
||||||
const upload_preset = fileType.startsWith("video")
|
const upload_preset = fileType.startsWith("video")
|
||||||
? "incoming_upload_video"
|
? "incoming_upload_video"
|
||||||
: "incoming_upload";
|
: "incoming_upload";
|
||||||
|
|
||||||
//Get the signed url.
|
//Get the signed url.
|
||||||
|
|
||||||
let signedURLResponse;
|
let signedURLResponse;
|
||||||
try {
|
try {
|
||||||
signedURLResponse = await axios.post(`${env.API_URL}/media/sign`, {
|
signedURLResponse = await axios.post(`${env.API_URL}/media/sign`, {
|
||||||
public_id: public_id,
|
public_id: public_id,
|
||||||
tags: tags,
|
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
|
|
||||||
upload_preset: upload_preset,
|
upload_preset: upload_preset,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -85,7 +76,6 @@ export const uploadToCloudinary = async (
|
|||||||
if (signedURLResponse.status !== 200) {
|
if (signedURLResponse.status !== 200) {
|
||||||
console.log("Error Getting Signed URL", signedURLResponse.statusText);
|
console.log("Error Getting Signed URL", signedURLResponse.statusText);
|
||||||
if (onError) onError(signedURLResponse.statusText);
|
if (onError) onError(signedURLResponse.statusText);
|
||||||
|
|
||||||
return { success: false, error: signedURLResponse.statusText };
|
return { success: false, error: signedURLResponse.statusText };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +102,6 @@ export const uploadToCloudinary = async (
|
|||||||
formData.append("upload_preset", upload_preset);
|
formData.append("upload_preset", upload_preset);
|
||||||
formData.append("api_key", env.REACT_APP_CLOUDINARY_API_KEY);
|
formData.append("api_key", env.REACT_APP_CLOUDINARY_API_KEY);
|
||||||
formData.append("public_id", public_id);
|
formData.append("public_id", public_id);
|
||||||
formData.append("tags", tags);
|
|
||||||
formData.append("timestamp", timestamp);
|
formData.append("timestamp", timestamp);
|
||||||
formData.append("signature", signature);
|
formData.append("signature", signature);
|
||||||
|
|
||||||
@@ -124,13 +113,11 @@ export const uploadToCloudinary = async (
|
|||||||
fileType
|
fileType
|
||||||
)}/upload`,
|
)}/upload`,
|
||||||
formData,
|
formData,
|
||||||
{
|
options
|
||||||
...options,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
// console.log("Cloudinary Upload Response", cloudinaryUploadResponse.data);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("CLOUDINARY error", error.response, cloudinaryUploadResponse);
|
console.log("CLOUDINARY error", error.response, cloudinaryUploadResponse);
|
||||||
|
if (onError) onError(error.message);
|
||||||
return { success: false, error: error };
|
return { success: false, error: error };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,35 +134,10 @@ export const uploadToCloudinary = async (
|
|||||||
//Insert the document with the matching key.
|
//Insert the document with the matching key.
|
||||||
const documentInsert = await client.mutate({
|
const documentInsert = await client.mutate({
|
||||||
mutation: INSERT_NEW_DOCUMENT,
|
mutation: INSERT_NEW_DOCUMENT,
|
||||||
|
|
||||||
update: (cache, { data }) => {
|
|
||||||
cache.modify({
|
|
||||||
fields: {
|
|
||||||
documents: (existingDocs = []) => {
|
|
||||||
const newDocRef = cache.writeFragment({
|
|
||||||
data: data.insert_documents.returning[0],
|
|
||||||
fragment: gql`
|
|
||||||
fragment newDoc on documents {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
key
|
|
||||||
type
|
|
||||||
takenat
|
|
||||||
extension
|
|
||||||
jobid
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
});
|
|
||||||
return [...existingDocs, newDocRef];
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
variables: {
|
variables: {
|
||||||
docInput: [
|
docInput: [
|
||||||
{
|
{
|
||||||
...(jobId ? { jobid: jobId } : {}),
|
...(jobId ? { jobid: jobId } : {}),
|
||||||
...(billId ? { billid: billId } : {}),
|
|
||||||
uploaded_by: uploaded_by,
|
uploaded_by: uploaded_by,
|
||||||
key: key,
|
key: key,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
@@ -197,19 +159,8 @@ export const uploadToCloudinary = async (
|
|||||||
status: "done",
|
status: "done",
|
||||||
key: documentInsert.data.insert_documents.returning[0].key,
|
key: documentInsert.data.insert_documents.returning[0].key,
|
||||||
});
|
});
|
||||||
// notification["success"]({
|
|
||||||
// message: i18n.t("documents.successes.insert"),
|
|
||||||
// });
|
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (onError) onError(JSON.stringify(documentInsert.errors));
|
if (onError) onError(JSON.stringify(documentInsert.errors));
|
||||||
// notification["error"]({
|
|
||||||
// message: i18n.t("documents.errors.insert", {
|
|
||||||
// message: JSON.stringify(JSON.stringify(documentInsert.errors)),
|
|
||||||
// }),
|
|
||||||
// });
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: JSON.stringify(documentInsert.errors),
|
error: JSON.stringify(documentInsert.errors),
|
||||||
@@ -234,6 +185,7 @@ export function formatBytes(a, b = 2) {
|
|||||||
if (0 === a || !a) return "0 Bytes";
|
if (0 === a || !a) return "0 Bytes";
|
||||||
const c = 0 > b ? 0 : b,
|
const c = 0 > b ? 0 : b,
|
||||||
d = Math.floor(Math.log(a) / Math.log(1024));
|
d = Math.floor(Math.log(a) / Math.log(1024));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
parseFloat((a / Math.pow(1024, d)).toFixed(c)) +
|
parseFloat((a / Math.pow(1024, d)).toFixed(c)) +
|
||||||
" " +
|
" " +
|
||||||
|
|||||||
@@ -52,40 +52,6 @@ export const handleLocalUpload = async ({
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
formData.append("jobid", jobid);
|
formData.append("jobid", jobid);
|
||||||
// const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
|
||||||
// const mimeType = mime.getType(imageData.uri);
|
|
||||||
|
|
||||||
// //let thumb;
|
|
||||||
// let fileData = {
|
|
||||||
// uri: null,
|
|
||||||
// type: null,
|
|
||||||
// name: null,
|
|
||||||
// };
|
|
||||||
// if (mimeType === "image/heic") {
|
|
||||||
// try {
|
|
||||||
// thumb = await ImageManipulator.manipulateAsync(imageData.uri, [], {
|
|
||||||
// format: "jpeg",
|
|
||||||
// base64: true,
|
|
||||||
// compress: 0.75,
|
|
||||||
// });
|
|
||||||
// const name = imageData.filename.split(".");
|
|
||||||
// name.pop();
|
|
||||||
// fileData = {
|
|
||||||
// uri: thumb.uri,
|
|
||||||
// type: "image/jpeg",
|
|
||||||
// name: name.join("") + ".jpeg",
|
|
||||||
// };
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log(error);
|
|
||||||
// onError && onError(error.message);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// fileData = {
|
|
||||||
// uri: imageData.localUri || imageData.uri,
|
|
||||||
// type: mimeType,
|
|
||||||
// name: filename,
|
|
||||||
// };
|
|
||||||
//}
|
|
||||||
|
|
||||||
const filesList = [];
|
const filesList = [];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
|||||||
@@ -4570,6 +4570,15 @@ expo-structured-headers@~2.2.0:
|
|||||||
resolved "https://registry.yarnpkg.com/expo-structured-headers/-/expo-structured-headers-2.2.1.tgz#739f969101de6bead921eee59e5899399ad67715"
|
resolved "https://registry.yarnpkg.com/expo-structured-headers/-/expo-structured-headers-2.2.1.tgz#739f969101de6bead921eee59e5899399ad67715"
|
||||||
integrity sha512-nY6GuvoS/U5XdhfBNmvXGRoGzIXywXpSZs2wdiP+FbS79P9UWyEqzgARrBTF+6pQxUVMs6/vdffxRpwhjwYPug==
|
integrity sha512-nY6GuvoS/U5XdhfBNmvXGRoGzIXywXpSZs2wdiP+FbS79P9UWyEqzgARrBTF+6pQxUVMs6/vdffxRpwhjwYPug==
|
||||||
|
|
||||||
|
expo-system-ui@~1.2.0:
|
||||||
|
version "1.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/expo-system-ui/-/expo-system-ui-1.2.0.tgz#dd8a80f11420cfc65ae25b7ce6de6b60a7aa5b0e"
|
||||||
|
integrity sha512-jynjFNz38FeY/2u4EKvLJdIk0hZAhicd9lbjSRJUDTjhGhQmYDsCQ32NKp/X3DwBkugAP5nwDwa5S3eGk5i80Q==
|
||||||
|
dependencies:
|
||||||
|
"@expo/config-plugins" "^4.0.14"
|
||||||
|
"@react-native/normalize-color" "^2.0.0"
|
||||||
|
debug "^4.3.2"
|
||||||
|
|
||||||
expo-updates-interface@~0.6.0:
|
expo-updates-interface@~0.6.0:
|
||||||
version "0.6.0"
|
version "0.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/expo-updates-interface/-/expo-updates-interface-0.6.0.tgz#cef5250106e59572afdfcf245c534754c8c844ba"
|
resolved "https://registry.yarnpkg.com/expo-updates-interface/-/expo-updates-interface-0.6.0.tgz#cef5250106e59572afdfcf245c534754c8c844ba"
|
||||||
|
|||||||
Reference in New Issue
Block a user