Merge branch 'feature/IOS-7-documents-should-upload-in-chronol' into release/1.1.0

This commit is contained in:
Patrick Fic
2021-05-21 08:32:31 -07:00
6 changed files with 58 additions and 40 deletions

View File

@@ -2,18 +2,18 @@
"expo": { "expo": {
"name": "imexmobile", "name": "imexmobile",
"slug": "imexmobile", "slug": "imexmobile",
"version": "1.0.12", "version": "1.1.0",
"orientation": "default", "orientation": "default",
"icon": "./assets/logo192noa.png", "icon": "./assets/logo192noa.png",
"ios": { "ios": {
"supportsTablet": true, "supportsTablet": true,
"bundleIdentifier": "com.imex.imexmobile", "bundleIdentifier": "com.imex.imexmobile",
"buildNumber": "1.0.12", "buildNumber": "1.1.0.1",
"googleServicesFile": "./GoogleService-Info.plist" "googleServicesFile": "./GoogleService-Info.plist"
}, },
"android": { "android": {
"package": "com.imex.imexmobile", "package": "com.imex.imexmobile",
"versionCode": 12, "versionCode": 1010001,
"googleServicesFile": "./google-services.json" "googleServicesFile": "./google-services.json"
}, },
"splash": { "splash": {

View File

@@ -52,12 +52,15 @@ export function ImageBrowserScreen({
const client = useApolloClient(); const client = useApolloClient();
async function handleOnSuccess(uri, id) { async function handleOnSuccess(uri, id) {
console.log("Succesful upload!", uri);
logImEXEvent("imexmobile_successful_upload"); logImEXEvent("imexmobile_successful_upload");
setUploads((prevUploads) => _.omit(prevUploads, uri)); setUploads((prevUploads) => _.omit(prevUploads, uri));
} }
const onDone = async (data) => { const onDone = async (data) => {
console.log(
"🚀 ~ file: screen-media-browser.component.jsx ~ line 60 ~ data",
data
);
logImEXEvent("imexmobile_upload_documents", { count: data.length }); logImEXEvent("imexmobile_upload_documents", { count: data.length });
//Validate to make sure the totals for the file sizes do not exceed the total on the job. //Validate to make sure the totals for the file sizes do not exceed the total on the job.
@@ -74,20 +77,21 @@ export function ImageBrowserScreen({
const totalOfUploads = await data.reduce(async (acc, val) => { const totalOfUploads = await data.reduce(async (acc, val) => {
//Get the size of the file based on URI. //Get the size of the file based on URI.
const info = await FileSystem.getInfoAsync(val.uri, { size: true }); const info = await FileSystem.getInfoAsync(val.uri, { size: true });
return (await acc) + info.size; return (await acc) + info.size;
}, 0); }, 0);
console.log( // console.log(
"Size of uploaded documents.", // "Size of uploaded documents.",
queryData.data.documents_aggregate.aggregate.sum.size, // queryData.data.documents_aggregate.aggregate.sum.size,
"Shop Limit", // "Shop Limit",
bodyshop.jobsizelimit, // bodyshop.jobsizelimit,
"Space remaining", // "Space remaining",
bodyshop.jobsizelimit - // bodyshop.jobsizelimit -
queryData.data.documents_aggregate.aggregate.sum.size, // queryData.data.documents_aggregate.aggregate.sum.size,
"Total of uploaded files", // "Total of uploaded files",
totalOfUploads // totalOfUploads
); // );
if ( if (
bodyshop.jobsizelimit - bodyshop.jobsizelimit -
@@ -108,12 +112,12 @@ export function ImageBrowserScreen({
let filename; let filename;
//Appears to work for android. //Appears to work for android.
//iOS provides the filename, android doe snot. //iOS provides the filename, android doe snot.
console.log("pid", p.id);
filename = p.filename || p.uri.split("/").pop(); filename = p.filename || p.uri.split("/").pop();
const result = await handleUpload( const result = await handleUpload(
{ {
//iOS provides the file name. Android does not. //iOS provides the file name. Android does not.
uri: p.uri,
filename, filename,
mediaId: p.id, mediaId: p.id,
onError: handleOnError, onError: handleOnError,
@@ -133,10 +137,7 @@ export function ImageBrowserScreen({
if (deleteAfterUpload) { if (deleteAfterUpload) {
try { try {
const result = await MediaLibrary.deleteAssetsAsync( await MediaLibrary.deleteAssetsAsync(ret.map((r) => r.mediaId));
ret.map((r) => r.mediaId)
);
console.log("Delete result :>> ", result);
} catch (error) { } catch (error) {
console.log("Unable to delete picture.", error); console.log("Unable to delete picture.", error);
} }

View File

@@ -1,12 +1,16 @@
import Constants from "expo-constants"; import Constants from "expo-constants";
import React from "react"; import React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Button, View } from "react-native"; import { Button, View, Text } from "react-native";
import { Title } from "react-native-paper"; import { Title } from "react-native-paper";
import { purgeStoredState } from "redux-persist"; import { purgeStoredState } from "redux-persist";
import SignOutButton from "../sign-out-button/sign-out-button.component"; import SignOutButton from "../sign-out-button/sign-out-button.component";
import * as Updates from "expo-updates";
export default function ScreenSettingsComponent() { export default function ScreenSettingsComponent() {
const { t } = useTranslation(); const { t } = useTranslation();
console.log(Constants.manifest);
return ( return (
<View <View
style={{ style={{
@@ -22,6 +26,7 @@ export default function ScreenSettingsComponent() {
number: Constants.manifest.version, number: Constants.manifest.version,
})} })}
</Title> </Title>
<Text>{Updates.releaseChannel}</Text>
<SignOutButton /> <SignOutButton />
<Button title="Purge State" onPress={() => purgeStoredState()} /> <Button title="Purge State" onPress={() => purgeStoredState()} />
</View> </View>

22
env.js
View File

@@ -1,5 +1,7 @@
import * as Updates from "expo-updates";
const ENV = { const ENV = {
dev: { test: {
API_URL: "https://api.test.imex.online", API_URL: "https://api.test.imex.online",
uri: "https://db.test.bodyshop.app/v1/graphql", uri: "https://db.test.bodyshop.app/v1/graphql",
wsuri: "wss://db.test.bodyshop.app/v1/graphql", wsuri: "wss://db.test.bodyshop.app/v1/graphql",
@@ -42,11 +44,19 @@ const ENV = {
}; };
function getEnvVars() { function getEnvVars() {
let env = process.env.NODE_ENV; if (process.env.NODE_ENV === "development") return ENV.test;
if (env === null || env === undefined || env === "") return ENV.dev;
if (env.indexOf("dev") !== -1) return ENV.dev; let releaseChannel = Updates.releaseChannel;
if (env.indexOf("staging") !== -1) return ENV.staging; if (
if (env.indexOf("prod") !== -1) return ENV.prod; releaseChannel === null ||
releaseChannel === undefined ||
releaseChannel === ""
)
return ENV.test;
if (releaseChannel.indexOf("development") !== -1) return ENV.test;
if (releaseChannel.indexOf("test") !== -1) return ENV.test;
if (releaseChannel.indexOf("default") !== -1) return ENV.prod;
else return ENV.prod; else return ENV.prod;
} }

View File

@@ -5,7 +5,7 @@ const INITIAL_STATE = {
cameraJob: null, cameraJob: null,
documentUploadInProgress: null, documentUploadInProgress: null,
documentUploadError: null, documentUploadError: null,
deleteAfterUpload: true, deleteAfterUpload: false,
}; };
const appReducer = (state = INITIAL_STATE, action) => { const appReducer = (state = INITIAL_STATE, action) => {

View File

@@ -12,19 +12,24 @@ 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 { uri, filename, mediaId, onError, onSuccess, onProgress } = ev; const { filename, mediaId, onError, onSuccess, onProgress } = ev;
const { bodyshop, jobId } = context; const { bodyshop, jobId } = context;
const newFile = await (await fetch(uri)).blob(); const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
let extension = ev.uri.split(".").pop();
const newFile = await (await fetch(imageData.localUri)).blob();
let extension = imageData.localUri.split(".").pop();
let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace( let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace(
/\.[^/.]+$/, /\.[^/.]+$/,
"" ""
)}`; )}`;
const res = await uploadToCloudinary( const res = await uploadToCloudinary(
key, key,
mediaId, mediaId,
imageData,
extension, extension,
newFile.type, newFile.type,
newFile, newFile,
@@ -39,6 +44,7 @@ export const handleUpload = async (ev, context) => {
export const uploadToCloudinary = async ( export const uploadToCloudinary = async (
key, key,
mediaId, mediaId,
imageData,
extension, extension,
fileType, fileType,
file, file,
@@ -57,7 +63,7 @@ export const uploadToCloudinary = async (
tagsArray ? tagsArray.map((tag) => `${tag},`) : "" tagsArray ? tagsArray.map((tag) => `${tag},`) : ""
}`; }`;
// let eager = process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS; // let eager = process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS;
console.log("fileType", fileType);
const upload_preset = fileType.startsWith("video") const upload_preset = fileType.startsWith("video")
? "incoming_upload_video" ? "incoming_upload_video"
: "incoming_upload"; : "incoming_upload";
@@ -91,10 +97,11 @@ export const uploadToCloudinary = async (
if (onProgress) onProgress({ percent: e.loaded / e.total }); if (onProgress) onProgress({ percent: e.loaded / e.total });
}, },
}; };
const formData = new FormData(); const formData = new FormData();
formData.append("file", { formData.append("file", {
uri: photo.uri, uri: imageData.localUri,
type: fileType, type: fileType,
name: file.data.name, name: file.data.name,
}); });
@@ -134,12 +141,7 @@ export const uploadToCloudinary = async (
if (onError) onError(cloudinaryUploadResponse.statusText); if (onError) onError(cloudinaryUploadResponse.statusText);
return { success: false, error: cloudinaryUploadResponse.statusText }; return { success: false, error: cloudinaryUploadResponse.statusText };
} }
console.log("mediaId", mediaId);
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
console.log(
"🚀 ~ file: document-upload.utility.js ~ line 140 ~ imageData",
imageData.creationTime
);
//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,